Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <map>
- #include <set>
- #include <ctime>
- #include <cassert>
- #include <queue>
- using namespace std;
- #define f first
- #define s second
- #define mp make_pair
- #define pb push_back
- #define forit(it,con) for (typeof(con.begin()) it = con.begin(); it != con.end(); ++it)
- #define f0(a) memset(a, 0, sizeof(a))
- #define all(v) v.begin(), v.end()
- #define pii pair<int,int>
- #define vi vector<int>
- #define ll long long
- #ifdef WIN32
- #define I64 "%I64d"
- #else
- #define I64 "%lld"
- #endif
- bool calced[52][52][52][4][4][2];
- int dp[52][52][52][4][4][2], a[10000], n, cnt[30];
- int Win(int c0, int c1, int c2, int fi, int se, bool who) {
- if (c0 == 0 && c1 == 0 && c2 == 0) {
- if (fi == 0 && se != 0) return 1;
- if (fi != 0 && se == 0) return 2;
- return 3;
- }
- int &ans = dp[c0][c1][c2][fi][se][who];
- if (calced[c0][c1][c2][fi][se][who]) return ans;
- // calced[c0][c1][c2][fi][se][who] = true;
- int t1, t2, t3;
- ans = 0;
- if (who == 0) {
- if(c0 > 0) t1 = Win(c0 - 1, c1, c2, fi, se, !who);
- if(c1 > 0) t2 = Win(c0 , c1 - 1, c2, (fi + 1) % 3, se, !who);
- if(c2 > 0) t3 = Win(c0, c1, c2 - 1, (fi + 2) % 3, se, !who);
- if (t1 == 1 || t2 == 1 || t3 == 1) {
- ans = 1;
- return ans;
- }
- if (t1 == 3 || t2 == 3 || t3 == 3) {
- ans = 3;
- return ans;
- }
- ans = 2;
- return ans;
- } else
- if (who == 1) {
- if(c0 > 0) t1 = Win(c0 - 1, c1, c2, fi, se, !who);
- if(c1 > 0) t2 = Win(c0 , c1 - 1, c2, fi, (se + 1) % 3, !who);
- if(c2 > 0) t3 = Win(c0, c1, c2 - 1, fi, (se + 2) % 3, !who);
- if (t1 == 2 || t2 == 2 || t3 == 2) {
- ans = 2;
- return ans;
- }
- if (t1 == 3 || t2 == 3 || t3 == 3) {
- ans = 3;
- return ans;
- }
- ans = 1;
- return ans;
- } else
- assert(false);
- }
- int main() {
- freopen("divisigame.in","r",stdin);
- freopen("divisigame.out","w",stdout);
- scanf("%d", &n);
- int x;
- for (int i = 0; i < n; ++i){
- scanf("%d", &x);
- while (x < 0) x += 3;
- cnt[x % 3]++;
- cerr << x % 3<< " " ;
- }
- memset(calced, 0, sizeof(calced));
- x = Win(cnt[0], cnt[1], cnt[2], 0, 0, 0);
- if (x == 1) puts("FIRST"); else
- if (x == 3) puts("DRAW"); else
- puts("SECOND");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment