QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#706528#6568. Space Alignmentucup-team902#AC ✓0ms3836kbC++171.6kb2024-11-03 12:01:042024-11-03 12:01:05

Judging History

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

  • [2024-11-03 12:01:05]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3836kb
  • [2024-11-03 12:01:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define fi first
#define se second
#define bg begin
#define gc getchar
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
	return f?res:-res;
}
template<typename tp>inline void chemx(tp &a,tp b){(a<b)?(a=b):0;}
template<typename tp>inline void chemn(tp &a,tp b){(a>b)?(a=b):0;}

cs int N=1005;

vector<pii> p[N];
int n;


int main(){
	#ifdef Stargazer
	freopen("1.in","r",stdin);
	#endif
	cin>>n;
	int dep=0;
	for(int j=1;j<=n;j++){
		string x;cin>>x;
		pii y;
		for(int l=x.length(),i=0;i<l;i++){
			if(x[i]=='s')y.se++;
			if(x[i]=='t')y.fi++;
			if(x[i]=='{'){
				p[dep].pb(y);
			//		cout<<j<<" "<<dep<<'\n';
				dep++;
			}
			if(x[i]=='}'){
				dep--;
				p[dep].pb(y);
			//	cout<<j<<" "<<dep<<'\n';
				
			}
		}
	}	
	int ans=-1;
	for(int i=0;i<=n;i++)if(p[i].size()){
		//cout<<i<<'\n';
		//for(pii x:p[i])cout<<x.fi<<" "<<x.se<<'\n';
		for(int j=0;j<p[i].size();j++)
		for(int k=j+1;k<p[i].size();k++){
			pii x=p[i][j],y=p[i][k];
			if(x.fi!=y.fi){
				int res=(y.se-x.se)/(x.fi-y.fi);
				if((y.se-x.se)%(x.fi-y.fi)!=0){
					puts("-1");return 0;
				}
				if(res<=0){
					puts("-1");return 0;
				}
				if(ans>0&&ans!=res){
					puts("-1");return 0;
				}
				ans=res;
			}
			else{
				if(x.se!=y.se){
					puts("-1");return 0;
				}
			}
		}
	}
	if(ans>=0)cout<<ans<<'\n';
	else cout<<1<<'\n';
}

详细

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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: 3820kb

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'