QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143086#6568. Space AlignmentUrgantTeam#WA 1ms3576kbC++231.8kb2023-08-20 15:54:312023-08-20 15:54:35

Judging History

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

  • [2023-08-20 15:54:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3576kb
  • [2023-08-20 15:54:31]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

#define int long

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, bal = 0;
    cin >> n;
    set < vector < int > > Cur;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        int S = 0, T = 0;
        for (auto c : s) {
            if (c == 's') S++;
            else if (c == 't') T++;
        }
        if (s.back() == '{') {
            if (bal) {
                Cur.insert({S, T, bal});
            }
            bal++;
        } else {
            bal--;
            if (bal) Cur.insert({S, T, bal});
        }
    }
    if (Cur.size() <= 1) cout << 1 << '\n';
    else {
        vector < vector < int > > cur;
        for (auto key : Cur) cur.push_back(key);
        //for (auto key : cur) cout << key[0] << " " << key[1] << " " << key[2] << endl;
        // (cur[0][0] + cur[0][1] * ans) * cur[1][2] = (cur[1][0] + cur[1][1] * ans) * cur[0][2]
        int ans = -1;
        for (int i = 0; i < cur.size(); i++) {
            for (int j = 0; j < cur.size(); j++) {
                if ((cur[i][1] * cur[j][2] - cur[j][1] * cur[i][2]) != 0) ans = (cur[j][0] * cur[i][2] - cur[i][0] * cur[j][2]) / (cur[i][1] * cur[j][2] - cur[j][1] * cur[i][2]);
            }
        }
        //cout << cur[0][0] << " " << cur[0][1] << " " << cur[0][2] << endl;
        //cout << cur[1][0] << " " << cur[1][1] << " " << cur[1][2] << endl;
        //cout << ans << endl;
        for (auto key : cur) {
            if ((key[0] + key[1] * ans) * cur[0][2] != (cur[0][0] + cur[0][1] * ans) * key[2]) {
                cout << "-1";
                exit(0);
            }
        }
        cout << ans << '\n';
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3460kb

input:

4
{
tt{
t}
}

output:

0

result:

wrong answer 1st lines differ - expected: '-1', found: '0'