QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#267130 | #6568. Space Alignment | Hongzy | AC ✓ | 1ms | 3948kb | C++17 | 1.6kb | 2023-11-26 23:01:29 | 2023-11-26 23:01:29 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define per(i, j, k) for(int i = j; i >= k; -- i)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 110;
int n, a[N], b[N], c[N];
int det(int a, int b, int c, int d) { //[a b][c d]
return a * d - b * c;
}
void check(int x, int y) {
if(x >= 1 && y >= 1) {
rep(i, 1, n) if(a[i] * x + b[i] * y != c[i]) return ;
printf("%d\n", x);
exit(0);
}
}
int main() {
scanf("%d", &n);
static char s[1024];
int o = 0, u = 0, v = 0;
rep(i, 1, n) {
scanf("%s", s);
int m = strlen(s);
int tab = 0, space = 0;
for(int j = 0; j < m - 1; j ++) {
tab += s[j] == 't';
space += s[j] == 's';
//tab = x, indent = y
//tab*x + (- o) y = - space
//ax + by = c
}
o -= (s[m-1] == '}');
a[i] = tab;
b[i] = -o;
c[i] = -space;
if(o == 1) {
if(!tab && !space) {
puts("-1");
exit(0);
}
u = tab;
v = space;
}
o += (s[m-1] == '{');
}
rep(i, 1, n) rep(j, i + 1, n) if(det(a[i], b[i], a[j], b[j]) != 0) {
int d = det(a[i], b[i], a[j], b[j]);
int x = det(c[i], b[i], c[j], b[j]);
int y = det(a[i], c[i], a[j], c[j]);
if(x % d || y % d) {
puts("-1");
exit(0);
}
x /= d; y /= d;
check(x, y);
puts("-1");
exit(0);
}
if(!u && !v) { //{}
puts("1");
exit(0);
}
int x, y;
check(1, u + v);
puts("-1");
exit(0);
return 0;
}
/*
2
{
}
4
{
tt{
sssst}
}
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3944kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3948kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3792kb
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: 3808kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'