QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#110946 | #6568. Space Alignment | USP_USP_USP# | WA | 2ms | 3496kb | C++20 | 1.3kb | 2023-06-04 23:22:40 | 2023-06-04 23:22:44 |
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 <= 2; 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: 0ms
memory: 3496kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3452kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3392kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3456kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3400kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3456kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3444kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 3460kb
input:
4 { tt{ ssss} }
output:
-1
result:
wrong answer 1st lines differ - expected: '2', found: '-1'