QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132449#6568. Space AlignmentSorting#AC ✓1ms3568kbC++850b2023-07-29 23:25:072023-07-29 23:25:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-29 23:25:10]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3568kb
  • [2023-07-29 23:25:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
int s[101],t[101];
int d[101];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	stack<int>st;
	for(int i=1; i<=n ;i++){
		string a;cin >> a;
		for(auto c:a){
			if(c=='s') s[i]++;
			else if(c=='t') t[i]++;
		}
		if(a.back()=='{') st.push(i);
		else{
			int x=st.size();
			d[st.top()]=x-1;
			d[i]=x-1;
			st.pop();
		}
	}/*
	for(int i=1; i<=n ;i++){
		
		cout << d[i] << ' ' << s[i] << ' ' << t[i] << endl;
	}*/
	for(int i=1; i<=1001 ;i++){
		bool ok=true;
		int ans=0;
		for(int j=1; j<=n ;j++){
			int cur=s[j]+t[j]*i;
			if(d[j]==0 || cur%d[j]!=0 || (ans!=0 && cur/d[j]!=ans)){
				if(cur!=0){
					ok=false;break;
				}
			}
			if(d[j]!=0) ans=cur/d[j];
		}
		if(!ok) continue;
		cout << i << '\n';
		return 0;
	}
	cout << "-1\n";
}

詳細信息

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'