QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#412600#6568. Space Alignmentgrass8cow#AC ✓4ms3892kbC++17865b2024-05-16 16:31:432024-05-16 16:31:44

Judging History

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

  • [2024-05-16 16:31:44]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3892kb
  • [2024-05-16 16:31:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
char c[1010];
int a[110],s1[1010],s2[1010];
int main(){
    scanf("%d",&n);
    for(int i=1,e,d=0;i<=n;i++){
        scanf("%s",c+1);e=strlen(c+1);
        int w;
        if(c[e]=='{')w=d,d++;
        else d--,w=d;
        for(int j=1;j<e;j++)if(c[j]=='s')s1[i]++;
        else s2[i]++;
        a[i]=w;
        //s1+s2x=dy
    }
    for(int x=1;x<=1000000;x++){
        bool fq=0;
        int y=-1;
        for(int i=1;i<=n;i++){
            int o=s1[i]+s2[i]*x;
            if(a[i]==0){
                if(o){fq=1;break;}
                continue;
            }
            if(o%a[i]){fq=1;break;}
            if(y!=-1&&y!=o/a[i]){fq=1;break;}
            else y=o/a[i];
        }
        if(fq)continue;
        printf("%d\n",x);return 0;
    }
    puts("-1");
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 4ms
memory: 3824kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'