QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354840 | #6568. Space Alignment | kevinshan# | AC ✓ | 0ms | 3864kb | C++17 | 3.4kb | 2024-03-16 04:22:14 | 2024-03-16 04:22:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define f first
#define s second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define For(i,a) FOR(i,0,a)
#define pi pair<int,int>
#define trav(a,b) for(auto& a:b)
map<int,set<pi>> M;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
if (fopen("input.in", "r")) {
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
}
int n;cin>>n;
int curDepth=0, mxDep=0;
For(i,n) {
int s=0,t=0;
string S;cin>>S;
For(j,S.size()) {
if(S[j]=='s') {
s++;
} else if(S[j]=='t') {
t++;
} else {
if(S[j]=='}') {
curDepth--;
}
// cout << i << " " << s << " A " << t << curDepth << endl;
mxDep = max(mxDep, curDepth);
M[curDepth].insert({s,t});
if(S[j]=='{') {
curDepth++;
} else {
// curDepth--;
}
}
}
}
// trav(x,M) {
// cout << x.f;
// trav(y,x.s) {
// cout << y.f << " " << y.s << " B ";
// }
// cout << endl;
// }
int tri = -1;
For(i,n)if(M[i].size()>1) {
pi A = *M[i].begin();
pi B = *(++M[i].begin());
if (tri==-1) {
if(A.s==B.s) {
cout << -1 << endl;
return 0;
} else {
tri = (B.f-A.f)/(A.s-B.s);
}
}
}
// cout << "A " << tri << mxDep << endl;
if(tri==-1) {
set<pi> diffs;
For(i,mxDep) {
assert(M[i].size()>0 && M[i+1].size()>0);
pi A = *M[i].begin();
pi B = *M[i+1].begin();
diffs.insert({A.f-B.f,A.s-B.s});
}
if (diffs.size()<=1) {
// cout << "A " << diffs.size() << endl;
if(diffs.size()==1 && (*diffs.begin()).f==0 && diffs.begin()->s==0) {
// cout << "HI" << endl;
cout << -1 << endl;
return 0;
} else {
cout << 1 << endl;
return 0;
}
}
pi A = *diffs.begin();
pi B = *(++diffs.begin());
if(B.s==A.s) {
cout << -1 << endl;
return 0;
} else {
tri = (B.f-A.f)/(A.s-B.s);
}
}
bool works = true;
if(tri<=0) {
cout << -1 << endl;
return 0;
}
assert(tri!=-1);
vector<int> v;
For(i,mxDep+1) {
int need = -1;
trav(x, M[i]){
int sum = x.f + tri*x.s;
if (need==-1) {
need=sum;
} else if(need!=sum) {
works = false;
}
}
assert(need!=-1);
v.pb(need);
}
if(v.size()>1) {
int K = v[1]-v[0];
if(K<=0) {
cout << -1 << endl;
return 0;
}
For(i,v.size()-1) if(v[i+1]-v[i]!=K) {
works = false;
}
}
if(!works) {
cout << -1 << endl;
} else {
cout << tri << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3636kb
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: 3596kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'