Submission #3427434
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
/*
<url:>
問題文============================================================
=================================================================
解説=============================================================
================================================================
*/
/*
update : k を x に変更
query : [s,t) の最小(大)を出力する
*/
const ll INIT = LINF;
struct SegTree {
int N;
ll init_v;
vector<ll> node;
SegTree(int _N):init_v(INIT) {
N = 1;
while (N < _N) N *= 2;
node.resize(2 * N - 1, init_v);
}
ll merge(ll l,ll r){
return min(l,r);
}
void build(){
for(int k = N - 2; k >= 0; k--){
node[k] = merge(node[2*k+1],node[2*k+2]);
}
}
void direct_update(int k,ll v){
node[k+N-1] = v;
}
void update(int k, ll val) {
k += N - 1;
node[k] = val;
while (k) {
k = (k - 1) / 2;
node[k] = merge(node[2 * k + 1], node[2 * k + 2]);
}
}
ll query(int a,int b){ return query(a,b,0,0,N);}
ll query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) return init_v;
if (a <= l && r <= b) return node[k];
else {
ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
return merge(vl, vr);
}
}
};
string solve(){
string res;
int N; cin >> N;
vector<int> C(N),A(N);
for(int i = 1; i < N;i++) cin >> C[i] >> A[i];
vector<int> grundy(N,-1);
grundy[0] = 0;
SegTree ST(1<<20);
for(int i = 0; i < (1<<20);i++) ST.direct_update(i,-1);
ST.direct_update(0, 0);
ST.build();
for(int i = 1; i < N;i++){
int L = i - C[i];
int R = 0;
for(int j = 19; j >= 0; j--){
if(ST.query(0,R+(1<<j))>=L){
R += 1<<j;
}
}
grundy[i] = R;
ST.update(R, i);
}
int Gnum = 0;
for(int i = 1; i < N;i++){
if(A[i]%2){
Gnum ^= grundy[i];
}
}
if(Gnum) res = "First";
else res = "Second";
return res;
}
int main() {
cin.tie(0); ios::sync_with_stdio(false);
cout << solve() << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
C - 茶碗と豆 |
User |
vjudge5 |
Language |
C++14 (GCC 5.4.1) |
Score |
104 |
Code Size |
3343 Byte |
Status |
AC |
Exec Time |
103 ms |
Memory |
17792 KB |
Judge Result
Set Name |
Sample |
Dataset1 |
Dataset2 |
Dataset3 |
Score / Max Score |
0 / 0 |
80 / 80 |
20 / 20 |
4 / 4 |
Status |
|
|
|
|
Set Name |
Test Cases |
Sample |
sample-01.txt, sample-02.txt, sample-03.txt |
Dataset1 |
sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt |
Dataset2 |
sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt |
Dataset3 |
01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 03-01.txt, 03-02.txt, 03-03.txt, 03-04.txt, 03-05.txt, 03-06.txt, 03-07.txt, 03-08.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
7 ms |
16640 KB |
01-02.txt |
AC |
7 ms |
16640 KB |
01-03.txt |
AC |
7 ms |
16640 KB |
01-04.txt |
AC |
7 ms |
16640 KB |
01-05.txt |
AC |
7 ms |
16640 KB |
01-06.txt |
AC |
7 ms |
16640 KB |
01-07.txt |
AC |
7 ms |
16640 KB |
01-08.txt |
AC |
8 ms |
16640 KB |
01-09.txt |
AC |
8 ms |
16640 KB |
01-10.txt |
AC |
7 ms |
16640 KB |
02-01.txt |
AC |
7 ms |
16640 KB |
02-02.txt |
AC |
7 ms |
16640 KB |
02-03.txt |
AC |
8 ms |
16640 KB |
02-04.txt |
AC |
7 ms |
16640 KB |
02-05.txt |
AC |
7 ms |
16640 KB |
02-06.txt |
AC |
7 ms |
16640 KB |
02-07.txt |
AC |
7 ms |
16640 KB |
02-08.txt |
AC |
8 ms |
16640 KB |
03-01.txt |
AC |
99 ms |
17792 KB |
03-02.txt |
AC |
99 ms |
17792 KB |
03-03.txt |
AC |
99 ms |
17792 KB |
03-04.txt |
AC |
99 ms |
17792 KB |
03-05.txt |
AC |
103 ms |
17792 KB |
03-06.txt |
AC |
102 ms |
17792 KB |
03-07.txt |
AC |
87 ms |
17792 KB |
03-08.txt |
AC |
87 ms |
17792 KB |
sample-01.txt |
AC |
7 ms |
16640 KB |
sample-02.txt |
AC |
7 ms |
16640 KB |
sample-03.txt |
AC |
8 ms |
16640 KB |