QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350013 | #8298. Erasing Numbers | ucup-team1209# | WA | 2ms | 3656kb | C++20 | 2.4kb | 2024-03-10 12:23:31 | 2024-03-10 12:23:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define cs const
#define pb push_back
using pi = pair <int, int> ;
cs int N = 5e3 + 5;
int T, n, a[N];
int o[N];
int p[N];
int ans[N];
pi chk(int l, int r) {
if(l > r) return pi(0, 0);
int a = 0, b = 0;
for(int i = l; i <=r ; i++) {
// a for 0, b for 1
// minimize 1
if(o[i] == 0) {
if(b > 1) -- b;
else if(a && b) -- b;
else ++ a;
}
else {
++ b;
if(b == 3) b -= 2;
}
}
while(a && b && a + b >= 3) -- a, -- b;
// cout << a << ' ' << b << endl;
pi ans;
if(!b) ans.first = -1;
else if(a) ans.first = 0;
else ans.first = 1;
a = 0, b = 0;
for(int i = l; i <=r ; i++) {
// a for 1, b for 0
// minimize 1
if(o[i] == 1) {
if(b > 1) -- b;
else if(a && b) -- b;
else ++ a;
}
else {
++ b;
if(b == 3) b -= 2;
}
}
swap(a, b);
while(a && b && a + b >= 3) -- a, -- b;
// cout << a << ' ' << b << endl;
if(!b) ans.second = -1;
else if(a) ans.second = 0;
else ans.second = 1;
// cout << "FF " << l << ' ' << r << ' ' << ans.first << ' ' << ans.second << endl;
assert(ans.first <= ans.second);
return ans;
}
bool in(int x, pi a) {
return x >= a.first && x <= a.second;
}
bool calc(pi a, pi b) {
if(in(0, a) && in(0, b)) return 1;
if(in(-1, a) && in(1, b)) return 1;
if(in(1, a) && in(-1, b)) return 1;
return 0;
}
void Main() {
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i], p[a[i]] = i;
for(int i = 1; i <= n; i++) o[i] = 1, ans[i] = 0;
for(int i = 1; i <= n; i++) {
pi a = chk(1, p[i] - 1);
pi b = chk(p[i] + 1, n);
// cout << i << ' ' << p[i] << ' ' << a.first << ' ' << a.second << ' ' << b.first << ' ' << b.second << endl;
if(calc(a, b)) ans[p[i]] = 1;
o[p[i]] = 0;
}
for(int i = 1; i <= n; i++) cout << ans[i];
cout << '\n';
}
int main() {
#ifdef zqj
freopen("1.in","r",stdin);
#endif
ios :: sync_with_stdio(0), cin.tie(0);
cin >> T;
while(T--) Main();
return 0;
}
/*
1 2 1 1 1 0
2 3 0 0 1 0
3 1 -1 -1 0 0
4 5 0 0 -1 -1
5 4 0 -1 -1 -1
00000
1 3 1 0 -1 -1
2 1 -1 -1 0 0
3 2 -1 -1 -1 -1
000
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
2 5 3 1 2 5 4 3 2 3 1
output:
10001 100
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3640kb
input:
1000 3 1 2 3 3 1 3 2 3 2 1 3 3 2 3 1 3 3 1 2 3 3 2 1 5 1 2 3 4 5 5 1 2 3 5 4 5 1 2 4 3 5 5 1 2 4 5 3 5 1 2 5 3 4 5 1 2 5 4 3 5 1 3 2 4 5 5 1 3 2 5 4 5 1 3 4 2 5 5 1 3 4 5 2 5 1 3 5 2 4 5 1 3 5 4 2 5 1 4 2 3 5 5 1 4 2 5 3 5 1 4 3 2 5 5 1 4 3 5 2 5 1 4 5 2 3 5 1 4 5 3 2 5 1 5 2 3 4 5 1 5 2 4 3 5 1 5 3...
output:
010 001 100 100 001 010 01110 01101 01010 01001 01010 01001 01010 01001 01000 01001 01000 01001 00010 00001 00100 00101 00001 00011 00011 00001 00101 00101 00001 00011 10110 10101 10010 10001 10010 10001 11010 11001 01000 11000 01000 11000 10010 10001 00100 10100 00001 10010 10011 10001 00101 10100 ...
result:
wrong answer 25th lines differ - expected: '00010', found: '00011'