Please sign in first.
Submission #42115561
Source Code Expand
#include <bits/stdc++.h>
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
const int N = 10;
int n;
string st[N];
struct Surreal {
ll n;
int d;
Surreal(ll _n = 0, int _d = 0) { n = _n, d = _d; }
inline friend Surreal operator + (const Surreal &x, const Surreal &y) {
int mx = max(x.d, y.d);
ll t = (x.n << (mx - x.d)) + (y.n << (mx - y.d));
int v = min(mx, __builtin_ctzll(t));
mx -= v;
t >>= v;
return Surreal(t, mx);
}
inline friend bool operator < (const Surreal &x, const Surreal &y) {
int mx = max(x.d, y.d);
return (x.n << (mx - x.d)) < (y.n << (mx - y.d));
}
inline friend bool operator > (const Surreal &x, const Surreal &y) {
return y < x;
}
inline friend bool operator <= (const Surreal &x, const Surreal &y) {
return !(y < x);
}
inline friend bool operator >= (const Surreal &x, const Surreal &y) {
return !(y > x);
}
inline friend Surreal operator - (const Surreal &x) {
return Surreal(-x.n, x.d);
}
inline friend Surreal operator | (Surreal x, Surreal y) {
assert(x < y);
if (x < 0 && 0 < y) return 0;
if (y <= 0) return -(-y | -x);
Surreal v((x.n >> x.d) + 1);
if (v < y) return v;
int d = max(x.d, y.d);
x.n <<= d - x.d;
y.n <<= d - y.d;
if (x.n + 1 == y.n) return Surreal(2 * x.n + 1, d + 1);
while ((x.n >> 1) + 1 < ((y.n + 1) >> 1)) {
x.n >>= 1, y.n = (y.n + 1) >> 1;
d--;
} assert(x.n + 1 == y.n - 1);
return Surreal(x.n + 1, d);
}
};
map <string, Surreal> mp;
Surreal calc(string st) {
if (mp.count(st)) return mp[st];
Surreal mx(-1e9), mn(1e9);
F(i, 1, n) {
if (st[i - 1] == '.' && st[i] == 'W') {
string stt = st;
swap(stt[i - 1], stt[i]);
chkmax(mx, calc(stt));
}
if (st[i - 1] == '.' && st[i] == 'B') {
string stt = st;
swap(stt[i - 1], stt[i]);
chkmin(mn, calc(stt));
}
if (st[i] == 'B') {
string stt = st;
stt[i] = '.';
chkmax(mx, calc(stt));
}
if (st[i] == 'W') {
string stt = st;
stt[i] = '.';
chkmin(mn, calc(stt));
}
}
// cout << st << " " << mx.n << " " << mx.d << " " << mn.n << " " << mn.d << " " << (mx | mn).n << " " << (mx | mn).d << endl;
return mp[st] = mx | mn;
}
signed main() {
read(n);
F(i, 1, n) {
string t; cin >> t;
F(j, 0, SZ(t)) st[j + 1] += t[j];
}
Surreal sum;
F(i, 1, n) sum = sum + calc(' ' + st[i]);
// cout << sum.n << ' ' << sum.d << endl;
puts(sum > 0 ? "Takahashi" : "Snuke");
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | H - Advance or Eat |
| User | ast123 |
| Language | C++ (GCC 9.2.1) |
| Score | 600 |
| Code Size | 3060 Byte |
| Status | AC |
| Exec Time | 17 ms |
| Memory | 3952 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 600 / 600 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, 059.txt, 060.txt, 061.txt, 062.txt, 063.txt, 064.txt, 065.txt, 066.txt, 067.txt, 068.txt, 069.txt, 070.txt, 071.txt, 072.txt, 073.txt, 074.txt, 075.txt, 076.txt, 077.txt, 078.txt, 079.txt, 080.txt, 081.txt, 082.txt, 083.txt, 084.txt, 085.txt, 086.txt, 087.txt, 088.txt, 089.txt, 090.txt, 091.txt, 092.txt, 093.txt, 094.txt, 095.txt, 096.txt, 097.txt, 098.txt, 099.txt, 100.txt, 101.txt, 102.txt, 103.txt, 104.txt, 105.txt, example0.txt, example1.txt, example2.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 13 ms | 3852 KiB |
| 001.txt | AC | 11 ms | 3836 KiB |
| 002.txt | AC | 12 ms | 3788 KiB |
| 003.txt | AC | 11 ms | 3720 KiB |
| 004.txt | AC | 2 ms | 3588 KiB |
| 005.txt | AC | 9 ms | 3736 KiB |
| 006.txt | AC | 2 ms | 3584 KiB |
| 007.txt | AC | 2 ms | 3584 KiB |
| 008.txt | AC | 14 ms | 3852 KiB |
| 009.txt | AC | 3 ms | 3600 KiB |
| 010.txt | AC | 9 ms | 3716 KiB |
| 011.txt | AC | 3 ms | 3480 KiB |
| 012.txt | AC | 8 ms | 3648 KiB |
| 013.txt | AC | 12 ms | 3792 KiB |
| 014.txt | AC | 13 ms | 3672 KiB |
| 015.txt | AC | 13 ms | 3812 KiB |
| 016.txt | AC | 14 ms | 3836 KiB |
| 017.txt | AC | 6 ms | 3640 KiB |
| 018.txt | AC | 10 ms | 3680 KiB |
| 019.txt | AC | 6 ms | 3668 KiB |
| 020.txt | AC | 9 ms | 3668 KiB |
| 021.txt | AC | 4 ms | 3556 KiB |
| 022.txt | AC | 2 ms | 3608 KiB |
| 023.txt | AC | 11 ms | 3824 KiB |
| 024.txt | AC | 10 ms | 3668 KiB |
| 025.txt | AC | 10 ms | 3800 KiB |
| 026.txt | AC | 9 ms | 3696 KiB |
| 027.txt | AC | 4 ms | 3672 KiB |
| 028.txt | AC | 3 ms | 3512 KiB |
| 029.txt | AC | 2 ms | 3448 KiB |
| 030.txt | AC | 3 ms | 3456 KiB |
| 031.txt | AC | 3 ms | 3452 KiB |
| 032.txt | AC | 2 ms | 3488 KiB |
| 033.txt | AC | 2 ms | 3608 KiB |
| 034.txt | AC | 2 ms | 3488 KiB |
| 035.txt | AC | 2 ms | 3564 KiB |
| 036.txt | AC | 2 ms | 3488 KiB |
| 037.txt | AC | 2 ms | 3604 KiB |
| 038.txt | AC | 2 ms | 3572 KiB |
| 039.txt | AC | 2 ms | 3492 KiB |
| 040.txt | AC | 2 ms | 3512 KiB |
| 041.txt | AC | 3 ms | 3608 KiB |
| 042.txt | AC | 2 ms | 3496 KiB |
| 043.txt | AC | 2 ms | 3564 KiB |
| 044.txt | AC | 2 ms | 3488 KiB |
| 045.txt | AC | 2 ms | 3528 KiB |
| 046.txt | AC | 2 ms | 3520 KiB |
| 047.txt | AC | 1 ms | 3532 KiB |
| 048.txt | AC | 2 ms | 3524 KiB |
| 049.txt | AC | 2 ms | 3472 KiB |
| 050.txt | AC | 2 ms | 3624 KiB |
| 051.txt | AC | 2 ms | 3588 KiB |
| 052.txt | AC | 4 ms | 3604 KiB |
| 053.txt | AC | 5 ms | 3500 KiB |
| 054.txt | AC | 3 ms | 3624 KiB |
| 055.txt | AC | 5 ms | 3528 KiB |
| 056.txt | AC | 5 ms | 3728 KiB |
| 057.txt | AC | 7 ms | 3676 KiB |
| 058.txt | AC | 6 ms | 3652 KiB |
| 059.txt | AC | 6 ms | 3672 KiB |
| 060.txt | AC | 4 ms | 3712 KiB |
| 061.txt | AC | 7 ms | 3576 KiB |
| 062.txt | AC | 17 ms | 3888 KiB |
| 063.txt | AC | 14 ms | 3952 KiB |
| 064.txt | AC | 15 ms | 3920 KiB |
| 065.txt | AC | 16 ms | 3928 KiB |
| 066.txt | AC | 13 ms | 3936 KiB |
| 067.txt | AC | 16 ms | 3808 KiB |
| 068.txt | AC | 3 ms | 3428 KiB |
| 069.txt | AC | 2 ms | 3572 KiB |
| 070.txt | AC | 2 ms | 3584 KiB |
| 071.txt | AC | 2 ms | 3512 KiB |
| 072.txt | AC | 2 ms | 3496 KiB |
| 073.txt | AC | 2 ms | 3516 KiB |
| 074.txt | AC | 3 ms | 3544 KiB |
| 075.txt | AC | 2 ms | 3524 KiB |
| 076.txt | AC | 2 ms | 3540 KiB |
| 077.txt | AC | 2 ms | 3424 KiB |
| 078.txt | AC | 2 ms | 3620 KiB |
| 079.txt | AC | 3 ms | 3612 KiB |
| 080.txt | AC | 4 ms | 3508 KiB |
| 081.txt | AC | 2 ms | 3600 KiB |
| 082.txt | AC | 3 ms | 3636 KiB |
| 083.txt | AC | 2 ms | 3512 KiB |
| 084.txt | AC | 2 ms | 3540 KiB |
| 085.txt | AC | 2 ms | 3484 KiB |
| 086.txt | AC | 3 ms | 3596 KiB |
| 087.txt | AC | 3 ms | 3576 KiB |
| 088.txt | AC | 3 ms | 3556 KiB |
| 089.txt | AC | 3 ms | 3508 KiB |
| 090.txt | AC | 2 ms | 3468 KiB |
| 091.txt | AC | 5 ms | 3580 KiB |
| 092.txt | AC | 3 ms | 3540 KiB |
| 093.txt | AC | 2 ms | 3608 KiB |
| 094.txt | AC | 3 ms | 3656 KiB |
| 095.txt | AC | 6 ms | 3560 KiB |
| 096.txt | AC | 7 ms | 3672 KiB |
| 097.txt | AC | 6 ms | 3592 KiB |
| 098.txt | AC | 8 ms | 3576 KiB |
| 099.txt | AC | 8 ms | 3752 KiB |
| 100.txt | AC | 9 ms | 3692 KiB |
| 101.txt | AC | 6 ms | 3728 KiB |
| 102.txt | AC | 7 ms | 3660 KiB |
| 103.txt | AC | 11 ms | 3748 KiB |
| 104.txt | AC | 8 ms | 3648 KiB |
| 105.txt | AC | 5 ms | 3628 KiB |
| example0.txt | AC | 3 ms | 3456 KiB |
| example1.txt | AC | 2 ms | 3560 KiB |
| example2.txt | AC | 2 ms | 3508 KiB |