QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#207765#6568. Space AlignmentFreeuni1#AC ✓1ms7604kbC++231.0kb2023-10-08 20:05:062023-10-08 20:05:06

Judging History

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

  • [2023-10-08 20:05:06]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:7604kb
  • [2023-10-08 20:05:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pb push_back
#define ARRS ((ll)(2e6 + 100))
#define MOD ((ll)998244353)
#define MAX ((ll)(1e9 + 100))
#define EP ((double)(1e-9))

ll cs[ARRS];
ll ct[ARRS];
ll dir[ARRS];

int main() {

	ll n;
	cin>>n;
	for(int i=0; i<n; i++){
		string s;
		cin>>s;
		for(int j=0; j<s.size(); j++){
			if(s[j]=='s')cs[i]++;
			if(s[j]=='t')ct[i]++;
		}
		if(s[s.size()-1]=='{') dir[i]=1;
		else dir[i]=-1;
	}
	for(ll wt=1; wt<=1010; wt++){
		ll ws = -1;
		ll cd = 0;
		ll good=1;

		for(int i=0; i<n; i++){
			if(dir[i]==-1)cd--;
			ll d = cd;
			ll cur = cs[i]+ct[i]*wt;
			if(d==0&&cur){
				good=0;
				break;
			}
			if(d){
				if(cur%d) {
					good=0;
					break;
				}
				ll cws = cur/d;
				if(ws==-1)ws=cws;
				if(ws!=cws){
					good=0;
					break;
				}
			}
			if(dir[i]==1)cd++;
		}
		// cout<<"g"<<good<<endl;
		if(good){
			cout<<wt<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7500kb

input:

10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5436kb

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5436kb

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 1ms
memory: 7572kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

score: 0
Accepted
time: 1ms
memory: 7508kb

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 1ms
memory: 7580kb

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 1ms
memory: 7604kb

input:

100
{
}
{
}
{
t{
ssssssssssssssssssssssssssssssssssss}
t{
t}
t{
tssssssssssssssssssssssssssssssssssss{
tssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss{
tsssssssssssssssssssssssssssssssssssst}
ttssssssssssssssssssssssssssssssssssss{
ssssssssssssssssssssssssssssssssssssssssss...

output:

36

result:

ok single line: '36'

Test #12:

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

input:

100
{
t{
tssssssssssssssssssss{
ttssssssssssssssssssss{
tsssssssssssssssssssstt{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{
ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...

output:

20

result:

ok single line: '20'

Test #13:

score: 0
Accepted
time: 1ms
memory: 7492kb

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'