QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140423 | #6568. Space Alignment | smosp# | AC ✓ | 18ms | 3576kb | C++23 | 1.3kb | 2023-08-15 21:32:13 | 2023-08-15 21:32:15 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >>n;
vector<int> spaces(n), tabs(n), indent(n);
int carry = 0;
for (int i =0; i < n; i++) {
string s;
cin >> s;
int l = (int)s.size();
for (int j = 0; j+1<l; j++) {
spaces[i] += (s[j] == 's');
tabs[i] += (s[j] == 't');
}
if (s[l-1] == '{') {
indent[i] = carry;
carry++;
} else if (s[l-1] == '}') {
carry--;
indent[i] = carry;
} else assert(false);
}
const int MAX_CHECK = 3e6;
int ans = -1;
for (int width = 1; width <= MAX_CHECK; width++) {
bool ok = true;
int64_t mult = -1;
for (int i = 0; i < n; i++) {
int64_t tot_width = int64_t(tabs[i])*width + spaces[i];
if (indent[i]) {
if (tot_width%indent[i] != 0) {
ok = false;
break;
}
int64_t this_mult = tot_width/indent[i];
if (mult != -1 && mult != this_mult) {
ok = false;
break;
}
mult = this_mult;
} else if (tot_width != 0) {
ok = false;
break;
}
}
if (!ok) continue;
ans = width;
break;
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 18ms
memory: 3444kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 18ms
memory: 3516kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 18ms
memory: 3468kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 18ms
memory: 3576kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3468kb
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: 3540kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'