QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#111013 | #6568. Space Alignment | Tobo# | AC ✓ | 25ms | 3500kb | C++20 | 1.6kb | 2023-06-05 13:55:44 | 2023-06-05 13:55:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define N 200005
void solve()
{
int n;
cin >> n;
vector<array<int, 3>> a(n + 1);
for (int i = 1; i <= n; i++)
{
string ss;
cin >> ss;
int s = 0, t = 0, z = 0;
for (char c : ss)
{
if (c == 's')
s++;
else if (c == 't')
t++;
else if (c == '{')
z++;
else
z--;
}
a[i] = {s, t, z};
}
for (int j = 1; j <= 1e6; j++)
{
vector<int> b(n + 1);
for (int i = 1; i <= n; i++)
b[i] = a[i][0] + a[i][1] * j;
bool is = 1;
int d = -1;
for (int i = 2; i <= n && is; i++)
{
if (a[i][2] != a[i - 1][2])
{
if (b[i] != b[i - 1])
is = 0;
}
else if (a[i][2] == 1)
{
if (d == -1)
d = b[i] - b[i - 1];
if (d <= 0 || d != b[i] - b[i - 1])
is = 0;
}
else
{
if (d == -1)
d = b[i - 1] - b[i];
if (d <= 0 || d != b[i - 1] - b[i])
is = 0;
}
}
if (is)
{
cout << j << '\n';
return;
}
}
cout << -1;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3408kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3408kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3396kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3468kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 25ms
memory: 3372kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 25ms
memory: 3472kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 25ms
memory: 3408kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 25ms
memory: 3464kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3384kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3500kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3416kb
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: 3432kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3404kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'