QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359353 | #6568. Space Alignment | nkamzabek# | WA | 12ms | 3840kb | C++23 | 1.4kb | 2024-03-20 16:51:52 | 2024-03-20 16:51:52 |
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], c[N];
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;
c[i] = bal;
if(d == 1) bal += d;
}
int ans = INT_MAX;
for(int C = 1; C <= 1000000; C++){
bool bad=0;
int target = -1;
for(int i = 1; i <= n; i++){
int rem = C*c[i] - cnt[i][0];
if(rem < 0) bad = 1;
if(!cnt[i][1])
continue;
if(rem % cnt[i][1]) bad = 1;
if(target == -1){
target = rem / cnt[i][1];
}
if(rem / cnt[i][1] != target){
bad = 1;
}
}
if(!bad){
if(target == -1) target = 1;
ans = min(ans, target);
}
}
if(ans == INT_MAX) ans = -1;
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 3788kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 4ms
memory: 3580kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 7ms
memory: 3840kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 3596kb
input:
4 { ss{ s} }
output:
1
result:
wrong answer 1st lines differ - expected: '-1', found: '1'