Submission #434848
Source Code Expand
#include <cassert>
#include <functional>
#include <set>
#include <ctime>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#ifndef ONLINE_JUDGE //POJ
# include <complex>
# include <random>
# include <array>
# define mkt make_tuple
# define empb emplace_back
#endif
#ifdef _LOCAL
# include "for_local.h"
#endif
using namespace std;
typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull;
#define repi(_I, _B, _E) for(int _I = (_B); (_I) < (_E); ++ (_I))
#define rep(_I, _N) for(int _I = 0; (_I) < (_N); ++ (_I))
#define mkp make_pair
#define all(_X) (_X).begin(), (_X).end()
inline int scani() { int n; scanf("%d", &n); return n; }
using pii = pair<int,int>;
int const O = 1, X = 2;
int bs[3][3];
int cs[3][3];
pii dfs(array<int, 3 * 3>& board, int mark) {
pii res { 0, 0 };
bool filled = true;
int score_ext;
rep(i, 3) rep(j, 3) {
if ( board[i * 3 + j] != 0 ) continue;
board[i * 3 + j] = mark;
pii&& p = dfs(board, O + X - mark);
board[i * 3 + j] = 0;
int const score = p.first - p.second;
if ( filled
|| (score - score_ext) * (mark == O ? 1 : -1) > 0 ) {
score_ext = score;
res = p;
filled = false;
}
}
if ( !filled ) {
return res;
} else {
pii p { 0, 0 };
rep(i, 3) rep(j, 3) {
if ( i + 1 < 3 ) {
(board[i * 3 + j] == board[(i + 1) * 3 + j] ? p.first : p.second)
+= bs[i][j];
}
if ( j + 1 < 3 ) {
(board[i * 3 + j] == board[i * 3 + (j + 1)] ? p.first : p.second)
+= cs[i][j];
}
}
return p;
}
}
signed main() {
rep(i, 2) rep(j, 3) {
cin >> bs[i][j];
}
rep(i, 3) rep(j, 2) {
cin >> cs[i][j];
}
array<int, 3 * 3> board;
fill(all(board), 0);
auto&& p = dfs(board, O);
cout << p.first << endl
<< p.second << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - 双子と○×ゲーム |
User |
vain0 |
Language |
C++11 (GCC 4.9.2) |
Score |
100 |
Code Size |
1981 Byte |
Status |
AC |
Exec Time |
83 ms |
Memory |
928 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 |
83 ms |
928 KB |
sample-02.txt |
AC |
79 ms |
800 KB |
test-01.txt |
AC |
79 ms |
920 KB |
test-02.txt |
AC |
78 ms |
920 KB |
test-03.txt |
AC |
78 ms |
804 KB |
test-04.txt |
AC |
78 ms |
796 KB |
test-05.txt |
AC |
78 ms |
672 KB |
test-06.txt |
AC |
77 ms |
672 KB |
test-07.txt |
AC |
77 ms |
800 KB |
test-08.txt |
AC |
77 ms |
804 KB |
test-09.txt |
AC |
79 ms |
800 KB |
test-10.txt |
AC |
79 ms |
924 KB |
test-11.txt |
AC |
78 ms |
804 KB |
test-12.txt |
AC |
80 ms |
676 KB |
test-13.txt |
AC |
80 ms |
804 KB |
test-14.txt |
AC |
78 ms |
920 KB |
test-15.txt |
AC |
81 ms |
792 KB |
test-16.txt |
AC |
79 ms |
808 KB |
test-17.txt |
AC |
78 ms |
808 KB |
test-18.txt |
AC |
79 ms |
796 KB |
test-19.txt |
AC |
82 ms |
808 KB |
test-20.txt |
AC |
78 ms |
676 KB |