QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#227614 | #6568. Space Alignment | Nerovix# | WA | 0ms | 3712kb | C++20 | 2.0kb | 2023-10-27 19:46:52 | 2023-10-27 19:46:53 |
Judging History
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;
}
if(n==2){
cout<<1<<"\n";
return;
}
int aa=a[2],bb=b[2],cc=k[2];
int t=0,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)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;
}
}
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: 3708kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3712kb
input:
4 { ss{ ss} }
output:
-1
result:
wrong answer 1st lines differ - expected: '1', found: '-1'