QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#647525#6843. PTSDN_z_AC ✓8ms5380kbC++236.3kb2024-10-17 14:34:242024-10-17 14:34:24

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 14:34:24]
  • 评测
  • 测评结果:AC
  • 用时:8ms
  • 内存:5380kb
  • [2024-10-17 14:34:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}

void init();void solve(int tc);
main()
{
	init();int t=1;
	cin>>t;
	for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
void solve([[maybe_unused]]int tc)
{
	int n;
	string s;
	cin>>n>>s;
	s=' '+s;
	long long ans=0,ex=0;
	for(int x=n;x>=1;x--)
	if(!ex||s[x]=='0')ex++;
	else ex--,ans+=x;
	cout<<ans<<endl;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

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: 1ms
memory: 3828kb

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: 1ms
memory: 3696kb

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: 1ms
memory: 3632kb

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: 1ms
memory: 3808kb

input:

1
100000
110101100111111011001110001010010000101001010111001011111000110010101010001110100000010011001111101010011100110001010101010000011110001010111001000001101010011011000110110011101010111011101110000000100100010101011100101010111101110010010111010000000110110100110010101110110011011101101111100...

output:

2494724745

result:

ok single line: '2494724745'

Test #7:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

1
100000
110010000110010001001011011011001010101001000011101101010100010111110111100011101110110100001101111001011001001010010111011110001001000100110111001011110001100110101000100000111101100001101101000010011100011110000101111011110010110101000111110100111010010100011010100101101001001001101111000...

output:

2489784303

result:

ok single line: '2489784303'

Test #8:

score: 0
Accepted
time: 8ms
memory: 5380kb

input:

1
1000000
01101101110111101001111011111000000011110001110001110001000111010100011010000101111100110100101100101001110100010011100011011110100110110000101100000111101110110100101100101000111000010100100010101101001011100110100010101011100011011011110010100100001011110111110001100010101101001100001101...

output:

249484810648

result:

ok single line: '249484810648'

Test #9:

score: 0
Accepted
time: 8ms
memory: 5324kb

input:

1
1000000
00101101100011110011010101100011011110110000011001000110100000100100011000101110100100000001110011100000100011111010110111100001100111010111010001010000000010000110100111110001000100111100111000110010111100111101010011111010010011100000010001101000111010001000001101100100111101010010010011...

output:

249734019860

result:

ok single line: '249734019860'

Test #10:

score: 0
Accepted
time: 8ms
memory: 5144kb

input:

1
1000000
10110000000110000000001000001000001110011000011000110011100101111010110111101100000101111111001011011010011111110000101001111100010000101001101110010010110001110111110000100101000011010101001010011010110101000100110011010001110110110000110100111011111001100010010001101010101101000000001010...

output:

249656813708

result:

ok single line: '249656813708'