Submission #18982644


Source Code Expand

Copy
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
//#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
typedef long double ld;

const int MAXN = 22222;
const int MAXM = 403;
struct Simplex{
  const double eps = 1E-10;
  double a[MAXN][MAXM], b[MAXN], c[MAXM], d[MAXN][MAXM];
  double x[MAXM];
  int ix[MAXN + MAXM]; // !!! array all indexed from 0
  // max{cx} subject to {Ax<=b,x>=0}
  // n: constraints, m: vars !!!
  // x[] is the optimal solution vector
  // usage : 
  // value = simplex(a, b, c, N, M);
  pair<double,bool> simplex(int n, int m){
    ++m;
    int r = n, s = m - 1;
    memset(d, 0, sizeof(d));
    for (int i = 0; i < n + m; ++i) ix[i] = i;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m - 1; ++j) d[i][j] = -a[i][j];
      d[i][m - 1] = 1;
      d[i][m] = b[i];
      if (d[r][m] > d[i][m]) r = i;
    }
    for (int j = 0; j < m - 1; ++j) d[n][j] = c[j];
    d[n + 1][m - 1] = -1;
    for (double dd;; ) {
      if (r < n) {
        int t = ix[s]; ix[s] = ix[r + m]; ix[r + m] = t;
        d[r][s] = 1.0 / d[r][s];
        for (int j = 0; j <= m; ++j)
          if (j != s) d[r][j] *= -d[r][s];
        for (int i = 0; i <= n + 1; ++i) if (i != r) {
          for (int j = 0; j <= m; ++j) if (j != s)
            d[i][j] += d[r][j] * d[i][s];
          d[i][s] *= d[r][s];
        }
      }
      r = -1; s = -1;
      for (int j = 0; j < m; ++j)
        if (s < 0 || ix[s] > ix[j]) {
          if (d[n + 1][j] > eps ||
              (d[n + 1][j] > -eps && d[n][j] > eps))
            s = j;
        }
      if (s < 0) break;
      for (int i = 0; i < n; ++i) if (d[i][s] < -eps) {
        if (r < 0 ||
            (dd = d[r][m] / d[r][s] - d[i][m] / d[i][s]) < -eps ||
            (dd < eps && ix[r + m] > ix[i + m]))
          r = i;
      }
      if (r < 0) return { 0 , false }; // not bounded
    }
    if (d[n + 1][m] < -eps) return { 0 , false }; // not executable
    double ans = 0;
    for(int i=0; i<m; i++) x[i] = 0;
    for (int i = m; i < n + m; ++i) { // the missing enumerated x[i] = 0
      if (ix[i] < m - 1){
        ans += d[i - m][m] * c[ix[i]];
        x[ix[i]] = d[i-m][m];
      }
    }
    return { ans , true }; 
  }
} solver;

int main(){
	ios::sync_with_stdio(false);
	int a[6], b[6];
	rep(i, 6) cin >> a[i];
	rep(i, 6) cin >> b[i];
	int var = 6;
	rep(j, 6){
		rep(i, var){
			solver.a[j][i] = 0.;
			if(j == i) solver.a[j][i] = 1.0;
		}
		solver.b[j] = 1.0;
	}
	rep(i, var){
		solver.a[6][i] = (ld)(a[i])/100.0L + (ld)(b[i])/100.0L;
	}
	solver.b[6] = 1.0;
	rep(i, var) solver.c[i] = (ld)(a[i])/100.0L;
	
	auto ans = solver.simplex(7, 6);
	printf("%.12f\n", ans.fi);
}

Submission Info

Submission Time
Task D - Dice Game
User IH19980412
Language C++ (GCC 9.2.1)
Score 1000
Code Size 4015 Byte
Status AC
Exec Time 58 ms
Memory 73756 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 41
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 58 ms 73688 KB
001.txt AC 51 ms 73636 KB
002.txt AC 52 ms 73640 KB
003.txt AC 55 ms 73640 KB
004.txt AC 55 ms 73712 KB
005.txt AC 54 ms 73520 KB
006.txt AC 51 ms 73616 KB
007.txt AC 55 ms 73652 KB
008.txt AC 56 ms 73648 KB
009.txt AC 51 ms 73520 KB
010.txt AC 53 ms 73708 KB
011.txt AC 50 ms 73692 KB
012.txt AC 52 ms 73740 KB
013.txt AC 55 ms 73692 KB
014.txt AC 54 ms 73688 KB
015.txt AC 57 ms 73520 KB
016.txt AC 51 ms 73524 KB
017.txt AC 51 ms 73676 KB
018.txt AC 51 ms 73616 KB
019.txt AC 58 ms 73676 KB
020.txt AC 55 ms 73648 KB
021.txt AC 53 ms 73692 KB
022.txt AC 51 ms 73640 KB
023.txt AC 52 ms 73684 KB
024.txt AC 51 ms 73712 KB
025.txt AC 53 ms 73736 KB
026.txt AC 49 ms 73676 KB
027.txt AC 53 ms 73752 KB
028.txt AC 54 ms 73580 KB
029.txt AC 48 ms 73756 KB
030.txt AC 55 ms 73712 KB
031.txt AC 57 ms 73684 KB
032.txt AC 55 ms 73708 KB
033.txt AC 58 ms 73672 KB
034.txt AC 53 ms 73524 KB
035.txt AC 57 ms 73712 KB
036.txt AC 49 ms 73688 KB
037.txt AC 53 ms 73708 KB
038.txt AC 52 ms 73704 KB
example0.txt AC 53 ms 73636 KB
example1.txt AC 52 ms 73648 KB