QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#409801 | #6843. PTSD | Kevin5307 | AC ✓ | 131ms | 28396kb | C++23 | 1.2kb | 2024-05-12 18:46:07 | 2024-05-12 18:46:08 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
bool flag[1001000];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
string s;
cin>>n>>s;
set<int> st;
ll ans=0;
for(int i=0;i<n;i++)
if(s[i]=='1')
st.insert(i);
for(int i=0;i<n;i++)
flag[i]=0;
for(int i=n-1;i>=0;i--)
if(!flag[i])
{
flag[i]=1;
while(sz(st)&&*st.rbegin()>=i)
st.erase(prev(st.end()));
if(sz(st))
{
int x=*st.rbegin();
st.erase(x);
flag[x]=1;
ans+=x+1;
}
}
cout<<ans<<endl;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
4 5 10101 8 11111111 4 1100 4 0110
output:
4 16 3 3
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
14 1 0 1 1 2 00 2 01 2 10 2 11 3 000 3 001 3 010 3 011 3 100 3 101 3 110 3 111
output:
0 0 0 0 1 1 0 0 2 2 1 1 2 2
result:
ok 14 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
2046 1 0 1 1 2 00 2 01 2 10 2 11 3 000 3 001 3 010 3 011 3 100 3 101 3 110 3 111 4 0000 4 0001 4 0010 4 0011 4 0100 4 0101 4 0110 4 0111 4 1000 4 1001 4 1010 4 1011 4 1100 4 1101 4 1110 4 1111 5 00000 5 00001 5 00010 5 00011 5 00100 5 00101 5 00110 5 00111 5 01000 5 01001 5 01010 5 01011 5 01100 5 0...
output:
0 0 0 0 1 1 0 0 2 2 1 1 2 2 0 0 3 3 2 2 3 3 1 1 4 4 3 3 4 4 0 0 4 4 3 3 4 4 2 2 6 6 5 5 6 6 1 1 5 5 4 4 5 5 3 3 6 6 5 5 6 6 0 0 5 5 4 4 5 5 3 3 8 8 7 7 8 8 2 2 7 7 6 6 7 7 5 5 8 8 7 7 8 8 1 1 6 6 5 5 6 6 4 4 9 9 8 8 9 9 3 3 8 8 7 7 8 8 6 6 9 9 8 8 9 9 0 0 6 6 5 5 6 6 4 4 10 10 9 9 10 10 3 3 9 9 8 8 ...
result:
ok 2046 lines
Test #4:
score: 0
Accepted
time: 11ms
memory: 3508kb
input:
5000 20 00111010010110111001 20 10010011111010101000 20 00010111100100000110 20 00100001011100011100 20 01111101100001000111 20 11111111001111010110 20 10101101101010111111 20 10001100110001011110 20 01110010001110110011 20 01010010101010011011 20 00010110111100100110 20 00110101101010110100 20 0001...
output:
90 87 65 79 70 97 99 81 90 82 87 95 92 88 94 43 87 53 38 87 66 86 85 98 98 93 84 92 95 95 77 73 85 70 75 80 73 56 73 90 66 75 54 86 96 94 66 67 66 69 98 80 97 67 88 80 86 94 78 84 61 88 85 69 92 92 94 93 94 92 90 61 93 69 88 87 95 87 85 80 95 95 96 78 81 75 97 62 57 89 74 93 87 86 95 78 99 84 78 98 ...
result:
ok 5000 lines
Test #5:
score: 0
Accepted
time: 6ms
memory: 3548kb
input:
100 1000 011000000000100100011000010000100000101011101101001000000100101100010110100001001101111001100110000101100110011111000100000011001011101110100000011010010011010100101110110011000011000001111011011000000100001000101111011010001100010011110010100100000110110010001000000110010001001110101110010...
output:
234602 243039 244012 245117 246145 245863 243437 236433 244688 236651 241886 229573 244349 235715 243163 243356 242377 241669 246219 240577 245717 243012 246876 244004 245984 247795 240421 247122 231424 247216 243569 240919 244124 220237 242291 245922 243454 243471 236283 246241 242644 246814 244583...
result:
ok 100 lines
Test #6:
score: 0
Accepted
time: 11ms
memory: 6124kb
input:
1 100000 110101100111111011001110001010010000101001010111001011111000110010101010001110100000010011001111101010011100110001010101010000011110001010111001000001101010011011000110110011101010111011101110000000100100010101011100101010111101110010010111010000000110110100110010101110110011011101101111100...
output:
2494724745
result:
ok single line: '2494724745'
Test #7:
score: 0
Accepted
time: 7ms
memory: 6108kb
input:
1 100000 110010000110010001001011011011001010101001000011101101010100010111110111100011101110110100001101111001011001001010010111011110001001000100110111001011110001100110101000100000111101100001101101000010011100011110000101111011110010110101000111110100111010010100011010100101101001001001101111000...
output:
2489784303
result:
ok single line: '2489784303'
Test #8:
score: 0
Accepted
time: 123ms
memory: 28396kb
input:
1 1000000 01101101110111101001111011111000000011110001110001110001000111010100011010000101111100110100101100101001110100010011100011011110100110110000101100000111101110110100101100101000111000010100100010101101001011100110100010101011100011011011110010100100001011110111110001100010101101001100001101...
output:
249484810648
result:
ok single line: '249484810648'
Test #9:
score: 0
Accepted
time: 126ms
memory: 28360kb
input:
1 1000000 00101101100011110011010101100011011110110000011001000110100000100100011000101110100100000001110011100000100011111010110111100001100111010111010001010000000010000110100111110001000100111100111000110010111100111101010011111010010011100000010001101000111010001000001101100100111101010010010011...
output:
249734019860
result:
ok single line: '249734019860'
Test #10:
score: 0
Accepted
time: 131ms
memory: 28380kb
input:
1 1000000 10110000000110000000001000001000001110011000011000110011100101111010110111101100000101111111001011011010011111110000101001111100010000101001101110010010110001110111110000100101000011010101001010011010110101000100110011010001110110110000110100111011111001100010010001101010101101000000001010...
output:
249656813708
result:
ok single line: '249656813708'