QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#730227#6568. Space Alignmentahsoltan#AC ✓0ms3860kbC++201.9kb2024-11-09 19:19:122024-11-09 19:19:13

Judging History

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

  • [2024-11-09 19:19:13]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3860kb
  • [2024-11-09 19:19:12]
  • 提交

answer

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
  o << "{";
  for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
  return o << "}";
}
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
  return o << "(" << x.first << ", " << x.second << ")";
}
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<ll> a(n), b(n), d(n);
  int dep = 0;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ll spa = 0;
    ll tab = 0;
    for(auto c : s) {
      if(c == 's')
        ++spa;
      else if(c == 't')
        ++tab;
    }
    int delta = s[sz(s) - 1] == '{' ? 1 : -1;
    if(delta == -1)
      --dep;
    a[i] = tab;
    b[i] = spa;
    d[i] = dep;
    if(delta == +1)
      ++dep;
  }

  ll x = 1e18;
  bool ok = true;
  for(int i = 0; i + 1 < n; i++) {
    ll num = b[i + 1] * d[i] - b[i] * d[i + 1];
    ll den = a[i] * d[i + 1] - a[i + 1] * d[i];
    if(den == 0) {
      if(num != 0) {
        ok = false;
        break;
      }
    } else {
      if(num % den != 0) ok = false;
      else {
        num /= den;
        if(x == 1e18) {
          if(num <= 0) {
            ok = false;
          }
          x = num;
        } else if(x != num) {
          ok = false;
        }
      }
      if(!ok) break;
    }
  }
  if(!ok) cout << -1 << endl;
  else {
    if(x == 1e18) x = 1;
    cout << x << endl;
  }
}

詳細信息

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'