QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#238930#6568. Space Alignmentpeddap#AC ✓1ms3792kbC++141.6kb2023-11-04 17:55:592023-11-04 17:55:59

Judging History

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

  • [2023-11-04 17:55:59]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3792kb
  • [2023-11-04 17:55:59]
  • 提交

answer

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

int32_t main() {
    int n;
    cin>>n;

    bool flag = true;
    int res = -1;
    stack<pair<int, int>> st;
    while (n--)
    {
        string s;
        cin>>s;
        if (s[s.size()-1]=='{')
        {
            int spaces = 0;
            int tabs = 0;
            for (int i=0;i<s.size()-1;i++)
            {
                if (s[i]=='s') spaces++;
                else tabs++;
            }
            st.push({spaces, tabs});
        }
        else
        {
            int s1 = 0;
            int t1 = 0;
            for (int i=0;i<s.size()-1;i++)
            {
                if (s[i]=='s') s1++;
                else t1++;
            }
            auto value = st.top();
            st.pop();
            auto s2 = value.first;
            auto t2 = value.second;
            if (t1==t2)
            {
                if (s1!=s2)
                {
                    flag = false;
                }
            }
            else if (t1>t2)
            {
                t1-=t2;
                s2-=s1;
                if (s2<=0||s2%t1!=0|| (res!=-1&&res!=s2/t1)) flag = false;
                res = s2/t1;
            }
            else
            {
                t2-=t1;
                s1-=s2;
                if (s1<=0||s1%t2!=0|| (res!=-1&&res!=s1/t2)) flag = false;
                res = s1/t2;
            }
        }
    }
    if (flag) {
        if (res==-1) cout<<1<<endl;
        else cout<<res<<endl;
    }
    else cout<<-1<<endl;

}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3532kb

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'