QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#110947 | #6568. Space Alignment | USP_USP_USP# | AC ✓ | 4ms | 3476kb | C++20 | 1.3kb | 2023-06-04 23:23:21 | 2023-06-04 23:23:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define pb push_back
void dbg_out() { cerr << endl; }
template<typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
const int MAXN = 2e5;
void solve() {
int n;
cin >> n;
vector<int> cnts(n), cntt(n), prof(n);
vector<string> s(n);
for(int i = 0; i < n; i++){
cin >> s[i];
}
int bal = -1;
for(int i = 0; i < n; i++){
for(auto c : s[i]){
if(c == 's') cnts[i]++;
if(c == 't') cntt[i]++;
if(c == '{'){
bal++;
prof[i] = bal;
}
if(c == '}'){
prof[i] = bal;
bal--;
}
}
}
for(int k = 1; k <= MAXN; k++){
bool serve = true;
int t = 1;
for(int i = 0; i < n; i++){
if(cntt[i] > 0){
int aux = k*prof[i]-cnts[i];
if(aux%cntt[i] != 0) serve = false;
t = aux/cntt[i];
break;
}
}
if(!serve) continue;
for(int i = 0; i < n; i++){
serve &= k*prof[i] == cnts[i] + cntt[i]*t;
}
if(serve){
cout << t << '\n';
return;
}
}
cout << -1 << '\n';
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int t = 1;
while(t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3452kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3396kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3404kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3408kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 4ms
memory: 3388kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 4ms
memory: 3416kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3412kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3416kb
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: 2ms
memory: 3420kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'