QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278633 | #6568. Space Alignment | ucup-team191# | AC ✓ | 0ms | 4148kb | C++14 | 959b | 2023-12-07 18:47:46 | 2023-12-07 18:47:47 |
Judging History
answer
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1050;
int n, x_s[N], x_t[N], dep[N];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
int depth = 0;
for(int i = 0;i < n;i++) {
string s; cin >> s;
if(s.back() == '}') depth--;
for(char c : s) x_s[i] += c == 's', x_t[i] += c == 't';
if(depth == 0 && x_s[i] + x_t[i] != 0) {
printf("-1\n");
return 0;
}
if(depth != 0 && x_s[i] + x_t[i] == 0) {
printf("-1\n");
return 0;
}
dep[i] = depth;
if(s.back() == '{') depth++;
}
int poc = 0;
while(poc < n && dep[poc] == 0) poc++;
if(poc == n) {
printf("1\n");
return 0;
}
for(int t = 1;t <= 1010;t++) {
int ind = (x_s[poc] + t * x_t[poc]) / dep[poc];
int ret = 1;
for(int i = 0;i < n;i++)
ret &= (x_s[i] + t * x_t[i]) == dep[i] * ind;
if(ret) {
printf("%d\n", t);
return 0;
}
}
printf("-1\n");
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3780kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4148kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3844kb
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: 0ms
memory: 3792kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'