QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227627#6568. Space AlignmentNerovix#AC ✓4ms3736kbC++203.4kb2023-10-27 20:09:162023-10-27 20:09:16

Judging History

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

  • [2023-10-27 20:09:16]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3736kb
  • [2023-10-27 20:09:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
#define db double
#define ll long long

const int maxn=1e2+10;
int n;
string s[maxn];
int a[maxn],b[maxn],k[maxn];
void calc(int a,int b,int c,int d,int e,int f,int&x,int&y){
    ll U=1ll*a*f-1ll*c*d;
    ll D=1ll*e*c-1ll*b*f;
    if(U%D){
        x=-1,y=-1;
        return;
    }
    x=U/D;
    if(x<=0){
        x=-1,y=-1;
        return;
    }
    U=a+1ll*b*x;
    D=c;
    if(U%D){
        x=-1;
        y=-1;
        return;
    }
    y=U/D;
    if(y<=0){
        x=y=-1;
        return;
    }
    return;
}
void solve(){
    cin>>n;
    int sta=0;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        if(s[i].back()=='{')k[i]=sta++;
        else if(s[i].back()=='}')k[i]=--sta;
        else assert(0);
        for(int j=0;j+1<s[i].size();j++){
            if(s[i][j]=='s')a[i]++;
            else assert(s[i][j]=='t'),b[i]++;
        }
        if(!(a[i]+b[i]+k[i]))continue;
        int g=__gcd(a[i],__gcd(b[i],k[i]));
        a[i]/=g;
        b[i]/=g;
        k[i]/=g;

    }
    for(int ans=1;ans<=1e6;ans++){
        int flag=0;
        int w;
        int bad=0;
        for(int i=1;i<=n;i++){
            int u=a[i]+b[i]*ans;
            if(k[i]==0){
                if(u==0){
                    continue;
                }
                else {
                    bad=1;
                    break;
                }
            }
            else{
                if(u%k[i]){
                    bad=1;
                    break;
                }
                else{
                    if(flag==0){
                        w=u/k[i];
                        flag=1;
                    }
                    else{
                        if(w!=u/k[i]){
                            bad=1;
                            break;
                        }
                        else continue;
                    }
                }
            }
        }
        if(bad||(flag==1&&w==0))continue;
        cout<<ans;
        return;
    }
    cout<<-1;
    return;
    // if(n==2){
    //     cout<<1<<"\n";
    //     return;
    // }
    // int aa=a[2],bb=b[2],cc=k[2];
    // int t=-2,w=0;
    // for(int i=3;i<n;i++){
    //     int d=a[i],e=b[i],f=k[i];
    //     if(1ll*e*cc==1ll*bb*f){
    //         if(1ll*aa*e==1ll*bb*d){
    //             aa+=d;
    //             bb+=e;
    //             cc+=f;
    //             continue;
    //         }
    //         else return cout<<"-1\n",void();
    //     }
    //     else{
    //         calc(aa,bb,cc,d,e,f,t,w);
    //         if(t==-1){
    //             cout<<-1<<"\n";
    //             return;
    //         }
    //         else break;
    //     }
    // }
    // if(t==-2){
    //     if(a==0&&b==0&&c==0){
    //         return cout<<1,void();
    //     }
    //     if(c==0)return cout<<-1,void();
    //     for(int t=1;t<=2e6;t++){
    //         if((aa+bb*t))
    //     }
    // }
    // for(int i=1;i<=n;i++){
    //     if(a[i]+b[i]*t!=k[i]*w){
    //         cout<<-1<<"\n";
    //         return;
    //     }
    // }
    // cout<<t<<"\n";
    return;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'