結果
| 問題 | No.3845 eval("G4M3") |
| コンテスト | |
| ユーザー |
noya2
|
| 提出日時 | 2026-12-03 05:02:24 |
| 結果 |
AC
不安定
|
| 実行時間 | 14 ms / 2,000 ms |
| + 647µs | |
| コード長 | 2,824 bytes |
| 記録 | |
| コンパイル時間 | 2,465 ms |
| コンパイル使用メモリ | 348,936 KB |
| 実行使用メモリ | 9,844 KB |
| 最終ジャッジ日時 | 2026-12-03 05:02:31 |
| 合計ジャッジ時間 | 5,916 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 49 |
ソースコード
#include<bits/stdc++.h>
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define all(v) begin(v),end(v)
using namespace std;
using ll = long long;
bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; }
bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a){
rep(i, 0, a.size()) os << (i ? " " : "") << a[i];
return os;
}
void dump(auto ...vs){
((cerr << vs << ' '), ...) << endl;
}
int win(vector<int> a){
int n = a.size();
unordered_map<int,int> memo;
auto dfs = [&](auto sfs, int s, int t) -> int {
int key = s | (t << (n-1));
if (memo.contains(key)){
return memo[key];
}
if (s == (1<<(n-1))-1){
int pre = -1;
int score = 0;
rep(i,0,n-1){
if (t >> i & 1) continue; // *
int mul = 1;
rep(j,pre+1,i+1){
mul &= a[j];
}
score ^= mul;
pre = i;
}
{
int mul = 1;
rep(j,pre+1,n){
mul &= a[j];
}
score ^= mul;
}
return memo[key] = score;
}
int who = (popcount<uint32_t>(s) & 1) ^ 1;
rep(i,0,n-1){
if (s >> i & 1) continue;
int ns = s ^ (1 << i);
rep(j,0,2){
int nt = t ^ (j << i);
int nxt = sfs(sfs,ns,nt);
if (who == nxt){
return memo[key] = who;
}
}
}
return memo[key] = 1^who;
};
return dfs(dfs,0,0);
}
int pred(vector<int> a){
int n = a.size();
if (n % 2 == 0){
if (a[0] != 0 || a[n-1] != 0){
return 1;
}
rep(i,1,n-1){
if (a[i] == 1 && a[i+1] == 1){
return 1;
}
}
return 0;
}
if (a[0] == a[n-1]){
return 0;
}
rep(i,0,n-1){
if (a[i] == 1 && a[i+1] == 1){
return 0;
}
}
return 1;
}
void jikken1(){
int n; cin >> n;
rep(s,0,1<<n){
vector<int> a(n);
rep(i,0,n){
a[i] = (s >> i & 1);
}
// dump(a,":",win(a),pred(a));
if (win(a) != pred(a)){
dump(a,":",win(a),pred(a));
}
// if (win(a) == (n & 1)){
// dump(a);
// }
}
}
void solve(){
int n; cin >> n;
string s; cin >> s;
vector<int> a(n);
rep(i,0,n){
a[i] = (int(s[i] - '0') & 1);
}
cout << (pred(a) == 1 ? "Alice" : "Bob") << '\n';
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t; cin >> t;
while (t--){
solve();
}
}
noya2