QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792227#6568. Space Alignmentlukamosiashvili#WA 0ms3720kbC++171.2kb2024-11-29 07:42:502024-11-29 07:42:50

Judging History

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

  • [2024-11-29 07:42:50]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2024-11-29 07:42:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int inf = -999999999;
string s[109];
char ch[109];
int spaces[109], tabs[109], ans = inf;

int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> s[i];
        ch[i] = s[i].back();
    }

    for(int i = 2; i <= n; i++){
        for(int j = 0; j < s[i].size() - 1; j++){
            if(s[i][j] == 's') spaces[i]++; else tabs[i]++;
        }

        int j = i - 1;
        if(ch[j] == '{' && ch[i] == '{') tabs[j]++;
        if(ch[j] == '}' && ch[i] == '}') tabs[j]--;

        if(spaces[j] == spaces[i] && tabs[j] == tabs[i]) continue;
        if(spaces[j] == spaces[i] || tabs[j] == tabs[i]){
            cout << -1;
            return 0;
        }

        int b = tabs[i] - tabs[j], a = spaces[j] - spaces[i];

        //cout << i << ": " << a << " " << b << "    " << ans << endl;

        if(a % b != 0){
            cout << -1;
            return 0;
        }

        int x = a / b;

        if(ans != inf && ans != x){
            cout << -1;
            return 0;
        }

        ans = x;
    }

    if(ans <= 0) cout << -1; else cout << ans;
    return 0;
}

详细

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3720kb

input:

2
{
}

output:

-1

result:

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