QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#354641#6568. Space AlignmentDelay_for_five_minutes#AC ✓1ms3692kbC++141.0kb2024-03-15 19:54:072024-03-15 19:54:07

Judging History

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

  • [2024-03-15 19:54:07]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3692kb
  • [2024-03-15 19:54:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=103;
int n,m,b[N];
pii a[N];
string s;
bool chk(int k){
    int t=-1,x;
    for(int i=1;i<=n;++i){
        x=k*a[i].second+a[i].first;
        if(b[i]==0)continue;
        if(x%b[i])return 0;
        if(t>0&&x/b[i]!=t)return 0;
        t=x/b[i];
    }
    return 1;
}
int main(){
    cin>>n;
    for(int i=1,d=0,o=-1;i<=n;++i){
        cin>>s;
        int x=0,y=0;
        for(int i=0;s[i]=='s'||s[i]=='t';++i){
            x+=s[i]=='s';
            y+=s[i]=='t';
        }
        if(s.back()=='{'){
            if(o==0)++d;
            o=0;
        }
        else if(s.back()=='}'){
            if(o==1)--d;
            o=1;
        }
        a[i]={x,y};
        b[i]=d;
        if(b[i]==0&&a[i]!=pii(0,0)){
            cout<<"-1\n";
            return 0;
        }
    }
    for(int k=1;k<=1000;++k)if(chk(k)){
        cout<<k<<'\n';
        return 0;
    }
    cout<<"-1\n";
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
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: 3480kb

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'