QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#128222#6568. Space Alignmentinstallb#AC ✓3ms3588kbC++141.1kb2023-07-20 18:37:482023-07-20 18:37:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 18:37:49]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3588kb
  • [2023-07-20 18:37:48]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define int long long

string t[105];
int n;

int solve(int y){
    int ans = -1;
    for(int ind = 0,i = 1;i <= n;i ++){
        string s = t[i];
        int len = s.length();
        if(s[len - 1] == '}') ind -= y;
        int a = 0,b = -ind;
        for(int j = 0;j < len - 1;j ++){
            if(s[j] == 's') b ++;
            if(s[j] == 't') a ++;
        }
        if(a == 0 && b != 0) return -1;
        if(a > 0){
            if(b >= 0) return -1;
            if(b % a != 0) return -1;
            int cur = -b / a;
            if(ans != -1 && ans != cur) return -1;
            ans = cur;
        }
        if(s[len - 1] == '{') ind += y;
    }
    if(ans == -1) ans = 1;
    return ans;
}

signed main(){
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> t[i];
    for(int i = 1;i <= 100000;i ++){
        int x = solve(i);
        if(x != -1){
            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: 3432kb

input:

10
{
ss{
sts{
tt}
t}
t{
ss}
}
{
}

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 3444kb

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3476kb

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 2ms
memory: 3580kb

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 3ms
memory: 3428kb

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 3ms
memory: 3448kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

score: 0
Accepted
time: 3ms
memory: 3404kb

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3408kb

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

score: 0
Accepted
time: 1ms
memory: 3588kb

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: 1ms
memory: 3452kb

input:

100
{
t{
tssssssssssssssssssss{
ttssssssssssssssssssss{
tsssssssssssssssssssstt{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstt{
ttsssssssssssssssssssstssssssssssssssssssssssssssssssssssssssss{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssstsssssssss...

output:

20

result:

ok single line: '20'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3372kb

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'