QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#239276#6568. Space Alignmentmtxas#AC ✓1ms3452kbC++141.5kb2023-11-04 19:42:242023-11-04 19:42:25

Judging History

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

  • [2023-11-04 19:42:25]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3452kb
  • [2023-11-04 19:42:24]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
//#define printf(...)
#define mp make_pair
using namespace std;
void solve()
{
    int n;
    cin>>n;
    int k = 0;
    vector<vector<int>> v;
    for(int i=1; i<=n; ++i){
        string s;
        cin>>s;
        if(s.back() == '}') k--;
        int cnts = 0, cntt = 0;
        for(int j=0; j<s.size(); ++j)
        {
            cnts += (s[j] == 's');
            cntt += (s[j] == 't');
        }
        v.push_back({k, cntt, cnts});
        if(s.back() == '{') k++;
    }
    for(int t=1; t< 10*1000 ; ++t){
//        printf("---------------------------\nt = %d\n", t);
        int ii = -1;
        bool ok = true;
        for(int i=0; i<n; ++i){
            int k = v[i][0];
            int cntt = v[i][1];
            int cnts = v[i][2];
            int R = cntt*t + cnts;
            if(k == 0) ok &= (R == 0);
            else{
                ok &= (R % k == 0);
                if(ok){
                    int curi = R/k;
                    if(ii == -1) ii = curi;
                    else ok &= (curi == ii);
                }
            }
//            printf("i = %d, ii = %d, ok = %d\n", i, ii, ok);
//            printf("(%d, %d, %d)\n", k, cntt, cnts);
        }
        if(ok){
            cout<<t;
            return;
        }
    }
    cout<<-1;
}
signed main()
{
//    freopen("input_00.txt", "r", stdin);
    int T = 1;
//    cin >> T;
    while(T--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3436kb

input:

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

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3452kb

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3400kb

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3316kb

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3392kb

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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: 3448kb

input:

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

output:

20

result:

ok single line: '20'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3388kb

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'