# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
482082 | Yazan_Alattar | Football (info1cup20_football) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int n, k;
map < pair < pair < int, vector <int> >, int > > dp;
int solve(int turn, vector <int> v, int mn)
{
int cnt = 0;
for(int i = 0; i < n; ++i) if(v[i]) ++cnt;
if(!cnt) return (turn % 2 ? 2 : 1);
int &ret = dp[{{turn, v}, mn}];
if(ret) return ret;
for(int i = 0; i < n; ++i){
for(int j = 1; j <= min(mn, v[i]); ++i){
v[i] -= j;
int res = solve(turn + 1, v, j);
if(ret == -1) ret = res;
if(turn % 2 && ret != 1) ret = res;
else if(turn % 2 == 0 && ret != 2) ret = res;
v[i] += j;
}
}
return ret;
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin >> t;
while(t--){
cin >> n >> k;
vector <int> v;
for(int i = 1; i <= n; ++i){
int x;
cin >> x;
v.pb(x);
}
cout << solve(1, v, 3) % 2;
}
return 0;
}
// Don't forget special cases. (n = 1?)
// Look for the constraints. (Runtime array? overflow?)