Submission #432581
Source Code Expand
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
int b[2][3], c[3][2];
pii memo[1 << 9][1 << 9];
pii rec(int x, int y) {
pii &r = memo[x][y];
if(r.first != -1) return r;
if(x == 0) {
int p[2] = {};
rep(i, 2) rep(j, 3)
p[(y >> (i * 3 + j) & 1) == (y >> ((i+1) * 3 + j) & 1)] += b[i][j];
rep(i, 3) rep(j, 2)
p[(y >> (i * 3 + j) & 1) == (y >> (i * 3 + (j+1)) & 1)] += c[i][j];
return r = mp(p[0], p[1]);
}
r = mp(0, 0);
int yy = ((~y & ((1 << 9)-1)) & ~x);
rep(i, 9) if(x >> i & 1) {
pii t = rec(x & ~(1 << i), yy | (1 << i));
amax(r, mp(t.second, t.first));
}
return r;
}
int main() {
while(1) {
rep(i, 2) rep(j, 3)
cin >> b[i][j];
rep(i, 3) rep(j, 2)
cin >> c[i][j];
if(!cin) break;
mset(memo, -1);
pii ans = rec((1 << 9)-1, 0);
cout << ans.first << '\n' << ans.second << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
C - 双子と○×ゲーム |
User |
anta |
Language |
C++ (GCC 4.9.2) |
Score |
100 |
Code Size |
2034 Byte |
Status |
AC |
Exec Time |
72 ms |
Memory |
2976 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
100 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt |
All |
test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
sample-01.txt |
AC |
27 ms |
2972 KB |
sample-02.txt |
AC |
28 ms |
2972 KB |
test-01.txt |
AC |
27 ms |
2724 KB |
test-02.txt |
AC |
27 ms |
2724 KB |
test-03.txt |
AC |
27 ms |
2976 KB |
test-04.txt |
AC |
27 ms |
2852 KB |
test-05.txt |
AC |
27 ms |
2840 KB |
test-06.txt |
AC |
27 ms |
2848 KB |
test-07.txt |
AC |
27 ms |
2848 KB |
test-08.txt |
AC |
27 ms |
2720 KB |
test-09.txt |
AC |
26 ms |
2856 KB |
test-10.txt |
AC |
27 ms |
2852 KB |
test-11.txt |
AC |
27 ms |
2848 KB |
test-12.txt |
AC |
26 ms |
2720 KB |
test-13.txt |
AC |
27 ms |
2848 KB |
test-14.txt |
AC |
28 ms |
2976 KB |
test-15.txt |
AC |
27 ms |
2848 KB |
test-16.txt |
AC |
27 ms |
2848 KB |
test-17.txt |
AC |
72 ms |
2852 KB |
test-18.txt |
AC |
28 ms |
2976 KB |
test-19.txt |
AC |
28 ms |
2720 KB |
test-20.txt |
AC |
26 ms |
2852 KB |