QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#140376#6568. Space Alignmentsmosp#WA 1ms3556kbC++171.2kb2023-08-15 20:13:382023-08-15 20:13:41

Judging History

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

  • [2023-08-15 20:13:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3556kb
  • [2023-08-15 20:13:38]
  • 提交

answer

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >>n;
  vector<int> spaces(n), tabs(n), indent(n);
  for (int i =0; i < n; i++) {
    string s;
    cin >> s;
    int l = (int)s.size();
    for (int j = 0; j+1<l; j++) {
      spaces[i] += (s[j] == 's');
      tabs[i] += (s[j] == 't');
    }
    if (s[l-1] == '{') {
      if (i) indent[i] += indent[i-1]+1;
    } else if (s[l-1] == '}') {
      if (i && i+1 < n) {
        indent[i] += indent[i-1];
        indent[i+1] += -1;
      }
    } else assert(false);
  }


  const int MAX_CHECK = 3e6;
  int ans = -1;
  for (int width = 1; width <= MAX_CHECK; width++) {
    bool ok = true;
    vector<int64_t> width_by_depth(n, -1);
    for (int i = 0; i < n; i++) {
      int64_t tot_width = int64_t(tabs[i])*width + spaces[i];
      if (indent[i]) {
        if (tot_width%indent[i] != 0) {
          ok = false;
          break;
        }
      } else if (tot_width != 0) {
        ok = false;
        break;
      }
    }
    if (!ok) continue;
    ans = width;
    break;
  }
  cout << ans << '\n';
}


详细

Test #1:

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

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

1

result:

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