QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#239116 | #6568. Space Alignment | Fyind# | AC ✓ | 1ms | 3468kb | C++17 | 1.5kb | 2023-11-04 18:40:45 | 2023-11-04 18:40:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define _ <<" "<<
#define sz(x) ((int) (x).size())
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 100 + 5;
int n, m;
int cnts[maxn], cntt[maxn], d[maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<char> st;
for (int i = 1;i <= n; ++i) {
string s; cin >> s;
for (auto c : s) {
if (c == '{') d[i] = sz(st),st.push_back('{');
else if (c == '}') st.pop_back(),d[i] = sz(st);
else if (c == 's'){
cnts[i]++;
} else cntt[i]++;
}
// cout << i _ d[i] << endl;
}
vector<int> pos;
for (int i = 1;i <= n; ++i) if (d[i]) pos.push_back(i);
if (pos.empty()) {
cout << 1 << endl;
return 0;
}
for (int x = 1;x <= 1000; ++x) if ((cnts[pos[0]] + cntt[pos[0]]*x) % d[pos[0]] == 0){
int y = (cnts[pos[0]] + cntt[pos[0]]*x) / d[pos[0]];
auto check = [&](int y) {
for (int i = 0;i < sz(pos); ++i) {
if ((cnts[pos[i]] + cntt[pos[i]]*x) % d[pos[i]] != 0) return false;
int ty = (cnts[pos[i]] + cntt[pos[i]]*x) / d[pos[i]];
if (ty != y) return false;
}
return true;
};
if (check(y)) {
cout << x << '\n';
return 0;
}
}
cout << -1 << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3356kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3388kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3396kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3460kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3388kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3420kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3424kb
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: 3468kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3400kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'