QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#599984#6568. Space AlignmentForever_Young#AC ✓6ms3956kbC++141.1kb2024-09-29 13:50:342024-09-29 13:50:34

Judging History

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

  • [2024-09-29 13:50:34]
  • 评测
  • 测评结果:AC
  • 用时:6ms
  • 内存:3956kb
  • [2024-09-29 13:50:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n;
char s[1005];
vector<pair<int,int>> v[105];
int main(){
    scanf("%d",&n);
    int dep=0;
    int max_dep=0;
    for (int i=0;i<n;i++){
        scanf("%s",s);
        int len=strlen(s);
        if (s[len-1]=='}') dep--;
        max_dep=max(max_dep,dep);
        int ns=0,nt=0;
        for (int j=0;j<len-1;j++)
            if (s[j]=='s') ns++; else nt++;
//            printf("%d %d %d\n",dep,ns,nt);
        v[dep].push_back({ns,nt});
        if (s[len-1]=='{') dep++;
    }

    for (int w=1;w<=1000000;w++){
        bool flag=true;
        int t2s = -1;
        for (int i=0;i<=max_dep&&flag;i++)
            for (auto x:v[i]){
                if (x.second>0&&t2s==-1){
                    t2s=(w*i-x.first)/x.second;
                }
                if (x.first+t2s*x.second!=w*i){
                    flag=false;
                    break;
                }
            }
        if (flag){
            if (t2s==-1) t2s=1;
            printf("%d\n",t2s);
            return 0;
        }
    }
    printf("-1");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 6ms
memory: 3740kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

score: 0
Accepted
time: 6ms
memory: 3888kb

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'