QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359330 | #6568. Space Alignment | nkamzabek# | WA | 0ms | 3808kb | C++23 | 1.2kb | 2024-03-20 16:34:15 | 2024-03-20 16:34:15 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define sz(s) (int)s.size()
#define int long long
using namespace std;
const int N = (int)5e5 + 100;
const int M = N + 7;
const int MOD = 998244353;
const int INF = (int)1e18 + 100;
int n, cnt[N][2];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
int bal = 0;
set<int> u;
for(int i = 1; i <= n; i++){
string s;
cin >> s;
int d = 1;
for(auto x : s){
if(x == 's')
cnt[i][0]++;
if(x == 't')
cnt[i][1]++;
if(x == '{')
d = 1;
else
d = -1;
}
if(d == -1) bal += d;
if(cnt[i][0] || cnt[i][1]){
int delta = bal - cnt[i][1];
if(delta){
int c = cnt[i][0] / (bal - cnt[i][1]);
if(cnt[i][0] % c || cnt[i][0] < c){
cout << "-1\n";
return 0;
}
u.insert(c);
}
}
if(d == 1) bal += d;
}
if(u.size() != 1) cout << "-1\n";
else{
cout << *u.begin() << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3584kb
input:
2 { }
output:
-1
result:
wrong answer 1st lines differ - expected: '1', found: '-1'