QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143088#6568. Space AlignmentUrgantTeam#WA 1ms3520kbC++231.4kb2023-08-20 15:58:442023-08-20 15:58:46

Judging History

This is the latest submission verdict.

  • [2023-08-20 15:58:46]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3520kb
  • [2023-08-20 15:58:44]
  • Submitted

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);
        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]);
            }
        }
        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: 3520kb

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

0

result:

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