QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143096#6568. Space AlignmentUrgantTeam#AC ✓1ms3592kbC++231.4kb2023-08-20 16:19:122023-08-20 16:19:15

Judging History

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

  • [2023-08-20 16:19:15]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3592kb
  • [2023-08-20 16:19:12]
  • 提交

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});
        }
    }
    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] || key[0] + ans * key[1] == 0) {
            cout << "-1";
            exit(0);
        }
    }
    if (ans <= 0) ans = -1;
    cout << ans << '\n';
    return 0;
}


详细

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'