QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792240 | #6568. Space Alignment | lukamosiashvili# | WA | 0ms | 3852kb | C++17 | 2.4kb | 2024-11-29 08:06:57 | 2024-11-29 08:06:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int inf = -999999999;
string s[109];
char ch[109], val[109];
int spaces[109], tabs[109], ans = inf;
int main(){
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> s[i];
ch[i] = s[i].back();
}
for(int i = 2; i <= n; i++){
for(int j = 0; j < s[i].size() - 1; j++){
if(s[i][j] == 's') spaces[i]++; else tabs[i]++;
}
int j = i - 1;
if(ch[j] == '{' && ch[i] == '{') continue;
if(ch[j] == '}' && ch[i] == '}') continue;
if(spaces[j] == spaces[i] && tabs[j] == tabs[i]) continue;
if(spaces[j] == spaces[i] || tabs[j] == tabs[i]){
cout << -1;
return 0;
}
int b = tabs[i] - tabs[j], a = spaces[j] - spaces[i];
//cout << i << ": " << a << " " << b << " " << ans << endl;
if(a % b != 0 || a / b < 0){
cout << -1;
return 0;
}
int x = a / b;
if(ans != inf && ans != x){
cout << -1;
return 0;
}
ans = x;
}
vector <pair <int, int> > v;
for(int i = 2; i <= n; i++){
int j = i - 1;
if(ch[j] != ch[i]) continue;
int b = tabs[i] - tabs[j], a = spaces[j] - spaces[i];
if(ch[j] == '}'){
b = -b;
a = -a;
}
// t (ans) *b - a const
v.push_back({b, a});
}
sort(v.begin(), v.end());
if(v.size() && v[0].first != v.back().first){
int q = v[0].second - v.back().second;
int w = v[0].first - v.back().first;
if(q % w != 0 || q / w < 0){
cout << -1;
return 0;
}
ans = q / w;
}
if(ans == inf) ans = 1;
//
for(int i = 1; i <= n; i++){
val[i] = ans * tabs[i] + spaces[i];
}
//
set <int> sx;
for(int i = 2; i <= n; i++){
if(ch[i] != ch[i - 1]){
if(val[i] != val[i - 1]){
cout << -1;
return 0;
}
}else{
if(ch[i] == '{') sx.insert(val[i] - val[i - 1]); else sx.insert(val[i - 1] - val[i]);
}
}
if(sx.size() > 1){
cout << -1;
return 0;
}
cout << ans;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3824kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: -100
Wrong Answer
time: 0ms
memory: 3568kb
input:
100 { } { } { t{ ssssssssssssssssssssssssssssssssssss} t{ t} t{ tssssssssssssssssssssssssssssssssssss{ tssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss{ tsssssssssssssssssssssssssssssssssssst} ttssssssssssssssssssssssssssssssssssss{ ssssssssssssssssssssssssssssssssssssssssss...
output:
-1
result:
wrong answer 1st lines differ - expected: '36', found: '-1'