QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152646 | #6568. Space Alignment | BUET_POISSON# | AC ✓ | 13ms | 3556kb | C++20 | 1.7kb | 2023-08-28 15:55:48 | 2023-08-28 15:55:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int M = 1000006;
const int N = 106;
string grid[N];
int level[N],scount[N],tcount[N];
signed main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>grid[i];
}
int lvl = 0;
for(int i=0;i<n;i++){
int s,t;
for(int j=0;j<grid[i].size();j++){
if( grid[i][j] == 's' ) scount[i]++;
if( grid[i][j] == 't' ) tcount[i]++;
if( grid[i][j] == '{' ) {
level[i] = lvl;
lvl++;
}
if( grid[i][j] == '}' ) {
lvl--;
level[i] = lvl;
}
}
//cout<<level[i]<<endl;
}
for(int i=0;i<n;i++){
if( level[i] == 0 and (tcount[i]+scount[i]) ){
cout<<-1<<endl;
return 0;
}
}
for(int i=1;i<M;i++){
int k = -1;
bool pos = true;
for(int j=0;j<n;j++){
if( level[j] == 0 ) continue;
int len = tcount[j]*i + scount[j];
if( len == 0 ){
pos = false;
}
if( len%level[j] != 0 ) {
pos = false;
break;
}
int temp = len/level[j];
// cout<<level[j]<<" "<<len<<" "<<temp<<endl;
if( k == -1 ) k = temp;
else if( k!= temp ) pos = false;
}
if( pos ){
cout<<i<<endl;
return 0;
}
}
cout<<-1<<endl;
}
/*
10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}
*/
/*
6
{
sss{
ts{
ts}
sss}
}
*/
/*
4
{
{
}
}
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3296kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3492kb
input:
2 { }
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
4 { ss{ ss} }
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
4 { tt{ tt} }
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 13ms
memory: 3356kb
input:
4 { ss{ s} }
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 13ms
memory: 3384kb
input:
4 { tt{ t} }
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 9ms
memory: 3380kb
input:
4 { tt{ s} }
output:
-1
result:
ok single line: '-1'
Test #8:
score: 0
Accepted
time: 13ms
memory: 3372kb
input:
4 { tt{ sss} }
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3360kb
input:
4 { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
6 { } { tt{ ssss} }
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3492kb
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: 3548kb
input:
100 { t{ tssssssssssssssssssss{ ttssssssssssssssssssss{ tsssssssssssssssssssstt{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{ ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...
output:
20
result:
ok single line: '20'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
4 { t{ sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...
output:
999
result:
ok single line: '999'