QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359352 | #6568. Space Alignment | nkamzabek# | WA | 2ms | 5860kb | C++23 | 1.4kb | 2024-03-20 16:51:29 | 2024-03-20 16:51:30 |
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 <= 100000; 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";
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5860kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3636kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5664kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5584kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5696kb
input:
4 { ss{ s} }
output:
1
result:
wrong answer 1st lines differ - expected: '-1', found: '1'