QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410312 | #6180. 滚动雪人游戏问题 | Max_s_xaM | 0 | 139ms | 5708kb | C++14 | 4.0kb | 2024-05-13 21:06:36 | 2024-05-13 21:06:36 |
Judging History
answer
#include <iostream>
typedef long long ll;
typedef double lf;
#define DEBUG 1
struct IO
{
#define MAXSIZE (1 << 20)
#define isdigit(x) (x >= '0' && x <= '9')
char buf[MAXSIZE], *p1, *p2;
char pbuf[MAXSIZE], *pp;
#if DEBUG
#else
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
#endif
#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
#define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
template <typename T>
void Read(T &x)
{
#if DEBUG
std::cin >> x;
#else
bool sign = 0; char ch = gc(); x = 0;
for (; !isdigit(ch); ch = gc())
if (ch == '-') sign = 1;
for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
if (sign) x = -x;
#endif
}
void Read(char *s)
{
#if DEBUG
std::cin >> s;
#else
char ch = gc();
for (; blank(ch); ch = gc());
for (; !blank(ch); ch = gc()) *s++ = ch;
*s = 0;
#endif
}
void Read(char &c) {for (c = gc(); blank(c); c = gc());}
void Push(const char &c)
{
#if DEBUG
putchar(c);
#else
if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
*pp++ = c;
#endif
}
template <typename T>
void Write(T x)
{
if (x < 0) x = -x, Push('-');
static T sta[35];
int top = 0;
do sta[top++] = x % 10, x /= 10; while (x);
while (top) Push(sta[--top] ^ 48);
}
template <typename T>
void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)
using namespace std;
const int MAXN = 1e4 + 10, N = 20;
pair <int, int> f[MAXN][MAXN];
inline pair <int, int> _F(int i, int j, int k, int x)
{
int c[3] = {0}; c[1] = i ^ j ^ k ^ max(i, max(j, k)), c[2] = max(i, max(j, k));
int res = f[c[1]][c[2]].first + x;
int g = f[c[1]][c[2]].second;
if (i == c[g]) g = 0;
else if (j == c[g]) g = 1;
else if (k == c[g]) g = 2;
return make_pair(res, g);
}
inline pair <int, int> F(int i, int j, int k)
{
int c0 = (i == 0) + (j == 0) + (k == 0);
if (c0 == 2) return make_pair(0, (i ? 0 : (j ? 1 : 2)));
pair <int, int> st[7]; int top = 0;
if (j >= i && i) st[++top] = _F(0, j - i, k + i, i);
if (i >= j && j) st[++top] = _F(i - j, 0, k + j, j);
if (k >= i && i) st[++top] = _F(0, j + i, k - i, i);
if (i >= k && k) st[++top] = _F(i - k, j + k, 0, k);
if (k >= j && j) st[++top] = _F(i + j, 0, k - j, j);
if (j >= k && k) st[++top] = _F(i + k, j - k, 0, k);
auto res = st[1];
for (int i = 2; i <= top; i++) res = min(res, st[i]);
int cc[7], num = 0;
for (int i = 1; i <= top; i++)
if (res.first == st[i].first) cc[++num] = st[i].second;
bool flag = 1;
for (int i = 1; i < num; i++)
if (cc[i] != cc[i + 1]) {flag = 0; break;}
if (flag) return make_pair(res.first, cc[1]);
else return make_pair(res.first, -1);
}
char str[MAXN];
int main()
{
// freopen("C.out", "w", stdout);
#if DEBUG
#else
ios::sync_with_stdio(0), cin.tie(0);
#endif
for (int tot = 1; tot <= N; tot++)
for (int i = 0; i * 2 <= tot; i++)
{
int j = tot - i;
if (i == 0) {f[i][j] = make_pair(0, 2); continue;}
f[i][j] = F(1, i - 1, j - 1), f[i][j].first++;
// cout << i << ' ' << j << " " << f[i][j].first << ' ' << f[i][j].second << "\n";
}
int n;
while (cin >> n)
{
cin >> str + 1;
int cnt[3] = {0};
for (int i = 1; i <= n; i++)
cnt[str[i] - 'A']++;
auto res = F(cnt[0], cnt[1], cnt[2]);
if (res.second == -1) cout << "N\n";
else cout << (char)(res.second + 'A') << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3608kb
input:
370 AAAABCCBBBACAABCAAAABBCCABACCBCCCCAAAAABBBCCACCBBBCBAABCABAABBCBAAAAABACBCAAAABBABBBBBBABCBBCCCACACABCCBBBABBBCACCBBAAABCACCACCABCAACBCCBBAABABCBCAAACABABCAAABCACCACCABCBCBCCCCCBCBCBACCCBACBCBBCBCCABCBABBCCBBAACCBBBCACBCBABBCABAABCCABCABBBABAABACACBBABBBCCACABCCCACABACCBBBBABABCBBBABABCCABAACAAB...
output:
C C N C A B A B C B B C A A C A B C B C A B A C B N C C A B B A C C B C A B C A B C N A A A C A N A C C A C C A A A B B C C C B B B C A B B A A C B C C C A B B B B B A C A A C C C B C A B C A C N A C A C B B A C B C C C N B B C A B B B A C A A B B N
result:
wrong answer 1st lines differ - expected: 'B', found: 'C'
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 5668kb
input:
909 CBABACBACABBCBCCCABCAAABCBCAACCCCBABACCABCBABCBABCABBBCCBBCCCABBCBABCBCBABABAAACACBBCCCBBCBCBCCBCCCACCBBABCBACCACCCBBBCBBACCACBCCCCAACCCACCABACACCCCBACCCCBAACBABAAAAACABBCABBCACCAABBBCCBCBAABCAAAAACBCACBBBBCCCCAAABBBBCCCBBAAACCACBCACCCBACCBCACCACAACCBCACCACBACAACBBAACBACAACAACABBCBAABACBACCBACCB...
output:
A A C C B B A A B C
result:
wrong answer 1st lines differ - expected: 'C', found: 'A'
Test #3:
score: 0
Wrong Answer
time: 139ms
memory: 5696kb
input:
1272 BACAAACACABABACACAAABCCCCCABCBCBBCACBABAAAACCAABCBBCCABBCABCAABBBAABCBBBBCBABACACCCCBCCBCBBBCCBABBAABAABCAABBAAAABBCBAAAACBCBBBAAAABBBCBCBACCBBCCCCCBBCBAACBBBBCACCCABBCACCBABCBACBBBACAABCCBACCCBABCBAACCBCCCCBCCCCCBAACCCBBBBCCBBAAABBCBBBAABBAACBAAACAABBBBBACBBCBBBACCBCCAACCACCBAACCBBBACBBBAACBCB...
output:
A B C A N B C A A B B C B A C C B B B B C A A C B C B C A A A A A B A C C C N C N C C C C C A A B C A C A B A B A B B C B C B C C C C B C B B A A A C C C C C C C A B C C C B A C B C C C B A C C C C A B B A C B A A C C N C B A C A A B B B C B B B B A A B C B B C C C N C A A C A B A A B A A A B B B A ...
result:
wrong answer 1st lines differ - expected: 'C', found: 'A'
Test #4:
score: 0
Wrong Answer
time: 114ms
memory: 5652kb
input:
9694 ACABACCAAABAABACBBACACBCBBCCACBACAAACCBCBCCCCBAACACCACCABBCAABCCBCCBBCABBCBAAACABABBAAAABBCBABCCBBBABACCACABACCACCABBAABACAAABABCCAABBBCAAABCBCAACABBCCCABAAAAABBCCCAAABAABBCACABABCCBAACCBCABABBABAABBBABBACCBAAABCABAABCCBAAAACABBCAABCBBAABABCBBCCBCBBBBCCBCCAABBCAAAACABAABBBACACACBAACABAACACACCBB...
output:
B B A C A A B C C A C C A A B A C B B B A A A C A C A A C A B B B C B C B A C A A A C B A C C B B A C A B C C B A B A C C A A A A C B A B A B B B A B B C A C C B B A A A B C A N B B C A C C B C C B B B C A A A B C B A B B C B A A C A B B B C B A C B A C A B C A B C B B B B B C B B C C A B B B A C A ...
result:
wrong answer 1st lines differ - expected: 'A', found: 'B'
Test #5:
score: 0
Wrong Answer
time: 47ms
memory: 5708kb
input:
5385 ABCAABBBACAAACCCBCACCBBACAACCBBBBCCABCCBACBBCCACAAAACBACABCCBAACCBCCABCBBAABAAACBAABABBCBCBCCCBBBBCABBCCBCACBAABABBBAACACCBCABCBCBBCCBABCCBBBCBCCBCBCBCBAAAACCAABBBCCBAACCACBAAACCBBAAABCABACBBABAACACCAACCACBAABBBAAABBCCAACBAACCBABABBACABCCCACCCACBBCACAABABCACAAAAACABACCCBBBBCCCBABACABAACCCCCACAA...
output:
B A A A C B A A B C C A A C B A C B A A B B A C C A C B C C B A A A C A C C C C A B C B B B A B B B B B B B B A B B C A A C C C B B A B C C C B A A B C A C B B B A B B C A A B C A B A A B C B A A C B A N B A A C B B B B B A C B B C B B B C A A B A C A C C A A B B B C C C C A B A C C A B A B A A B C ...
result:
wrong answer 1st lines differ - expected: 'A', found: 'B'
Test #6:
score: 0
Wrong Answer
time: 59ms
memory: 3676kb
input:
7790 CABACACCCAAACBBABAAABCBCBCBCBACAACBCBBBCABACBACBBAAACBBCACABABBCBBBCCABBAAACBACABCCCCBBAACCCBABCBCBCAAAAACCBBBCABCBCCACBACCBABAABAABCBCBBBABBBCBABAACBCBACACBCABCBCBBACBBCCCCCACAAACABBCBACCABBCBACCABBBCCCACBCBACAAACABCAACBCABCBCCCACAAAACBBBACCAAABCBAABCACBCCABBAAACACCCBABABBBCABBACBBBBACBBBBBCAA...
output:
B B C C A B B A A C C C C C B C B A C B A B A A B C A B C A A A C A C C B C C C A B A A B C A B N C A C C B B A A B A A B A A B A B B C C A A C B B A A C B C B C A C A B A B B C B A C A C C A C B C A B C C A B A A B A C B A A A B C C A C C B C B A C C C C C A C A A A A A C C A B C B C C B C C B A A ...
result:
wrong answer 1st lines differ - expected: 'A', found: 'B'
Test #7:
score: 0
Wrong Answer
time: 80ms
memory: 3644kb
input:
8580 BACCABCCBABBBCCBBACACACBBBABBCABCAACBCBBBBABBAAAACCACABCCBABCBCCBACCCBCBCCABCCCCBCCBCACBBACCCACBCCBCCAACBBCBABCABCCABCBCCBBAAACCACABCCCABABAACBCBCAAAAACCCCBABBAABBBAACBCCCCABBBBCCABCCABCCCABABAABBCCAABBBBBAAACAAACCCAABBACABACABACCACBCBBBACACCCAACCBBBAACABCCBBACBCCACABCBACCCCABCCCBCAAABAABBAACCB...
output:
A A C A C C A C B A C A C A B B A A C C C A C B B B B C A C A A A A B C B B A C A A C N A B C C C A C C B C A A A A B C A C A N B A C C C A B A C B B B B B B B A A B A C A C C A A A A A A B A A B B B C C B B A A A B A B C A B A A C B A B C A B B B B B N C A A A B B C A C A B A A B B B A A B A C B A ...
result:
wrong answer 2nd lines differ - expected: 'C', found: 'A'
Test #8:
score: 0
Wrong Answer
time: 83ms
memory: 3644kb
input:
5296 BCAABBBCABBCBCCBAAAABABBBACACACABBACACBACCCBBACCCCCCAAACCBCAABCBACBCCACABACCABBBBBCCACCBCBBCCCACAABACACAAACABCBCABCBCCABCCACACCCCBBACAACCBABBCBBBBABACABBBACBABCBBAAABAAACBACCBCCCBCCAACBACABCCCBAAACBAABAACBBCBACACCABCBCACACCCAACACACBCBCBBCCBBBBBCCBCCCAACABBAABAACBCACBACBCACBAACAAAAAACBABABBCBAAC...
output:
B B C C B C A A B B B A A A C A A C C C A B A B B C A B B B A A C B B C A A B C C B B C C C C A A A C B C A A C B C A B C C B A A B C B B C A A A A A A A A B C A B A C A C C B B C C A B C B B C A B C B C A B B C B B A C A C B B B B C A A C B A C C B C B A C B C B A B B A B C C B A C B B A B C B B A ...
result:
wrong answer 1st lines differ - expected: 'C', found: 'B'
Test #9:
score: 0
Wrong Answer
time: 93ms
memory: 5668kb
input:
5195 AACCCCACABACBAAAACBAABBACAAAABBBBCBAAAABCCCACAABCBCAAABBBABBCCABABCCABBCBACBBBCBCCBCBCABABCAABACBAAACBBBABCBBCBCBAABACCABBBCBBBBCBACCCCCBCAAACACAAACBAAAACCCAABCCCCACAABCCCAABABAABAAABCBCCAAAACBAABBBACBBACCCCCABBBAABACCCAACABBABBAACBBBBBBCABBBACCCACCBBBACCABAACCBABAACBBCCBCABCBABCBABBCCAABBAACCB...
output:
A A B C B C B C B B C A B A C C C C A C C C A C A A A B C C A C C C C B A C A A B B B B B C A B A A C B C C C C C C B C B C C C A C B C B B C B A C C A A A A B B B A B B A B B A C B A C A B C A B A A B B B C A C C A B A C C C B B A A A C A B A B A B A B A A A A B B C C B A B C A C B A A B B C A A C ...
result:
wrong answer 2nd lines differ - expected: 'C', found: 'A'
Test #10:
score: 0
Wrong Answer
time: 127ms
memory: 3672kb
input:
8526 BACBCCAACBBABABACBBBCBCAACCBBBCBABBBCBAABCACACCBBBAACCAABACBBCBAACCBABBAACBACBACCBCCAAABCAAAAAABBCABCBABBCCBBBBCCAACBCBABBBBBAACACBCBAAAABBBABBBAABBBBCBABBABBBAACCAABAACAACBCBBCBCABACCCBBAABCABCCBCAACCCCABBCCBBACBABABCCACAABCACBABACBCBCACBBAABCBAABBCABBCBABACCACCBBBACBCBCACAABBBACACBBBABCABAACB...
output:
B B C C C C C A B B A B C C B A A A A C B B B B B C C B A A C A B C A A B C A C B C C A B C A A C A B A C C A C C B C A B A C C A B C C A A A B B B B B C A C A A A B A A C B C C B B B C B C A B C C A A C B B B C A A A A A C A C C A B A B A A A C C A B C B C A B B A C C A B A C C C C C B B A A B B C ...
result:
wrong answer 1st lines differ - expected: 'A', found: 'B'