QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111040#6568. Space AlignmentOOBMABTRAMS#AC ✓3ms3532kbC++171.1kb2023-06-05 16:53:222023-06-05 16:53:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-05 16:53:23]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3532kb
  • [2023-06-05 16:53:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1013,mod=998244353;
typedef long long ll;
typedef long double ld;
int input=0;
const ll inf=2e18;
//i day j site
string s[N];
int k[N],b[N],d[N],v[N];
void solve(){
    int dep=0,n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        d[i]=dep;
        if(s[i].back()=='{')dep++;else dep--,d[i]--;
        for(auto c:s[i])if(c=='s')b[i]++;else if(c=='t')k[i]++;
    }
    int t=-1,f=1;
    for(int x=1;x<=100000;x++){
        t=-1,f=1;
        for(int i=1;i<=n;i++){
            v[i]=k[i]*x+b[i];
            if(!d[i]&&!v[i])continue;
            if(!d[i]&&v[i]||v[i]%d[i]){
                f=0;break;
            }else if(~t&&t!=v[i]/d[i]){
                f=0;break;
            }else{
                t=v[i]/d[i];
            }
        }
        if(f){
            cout<<x<<'\n';return;
        }
    }
    cout<<-1<<'\n';
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cout<<fixed<<setprecision(10);
    int T;
    if(input)cin>>T;else T=1;
    for(int tc=1;tc<=T;tc++)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3440kb

input:

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

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3440kb

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3328kb

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3532kb

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3372kb

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 3ms
memory: 3480kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

score: 0
Accepted
time: 3ms
memory: 3528kb

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3380kb

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

score: 0
Accepted
time: 2ms
memory: 3500kb

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 2ms
memory: 3392kb

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: 2ms
memory: 3336kb

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'