QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#354839 | #6568. Space Alignment | kevinshan# | WA | 1ms | 3848kb | C++17 | 3.4kb | 2024-03-16 04:21:34 | 2024-03-16 04:21:34 |
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) {
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: 3796kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3544kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 3772kb
input:
4 { tt{ sss} }
output:
1
result:
wrong answer 1st lines differ - expected: '-1', found: '1'