QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#277051#6568. Space Alignmentucup-team1198#AC ✓0ms3820kbC++142.2kb2023-12-06 14:58:442023-12-06 14:58:44

Judging History

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

  • [2023-12-06 14:58:44]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3820kb
  • [2023-12-06 14:58:44]
  • 提交

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>

using namespace std;


int main() {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#endif

  int n;
  cin >> n;
  int s1 = -1, t1 = -1, k1 = -1;
  int k2 = 0;
  int x = -1, y = -1;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (s.back() == '}') --k2;
    if (i != 0 && i != n - 1) {
      int s2 = 0, t2 = 0;
      for (auto ch : s) {
        if (ch == 's') ++s2;
        if (ch == 't') ++t2;
      }
      /// cerr << s2 << " " << t2 << " " << k2 << endl;
      /// cerr << x << " " << y << endl;
      if (x != -1) {
        if (s2 + t2 * x != k2 * y) {
          cout << "-1\n";
          return 0;
        }
      } else {
        if (s2 != 0 || t2 != 0 || k2 != 0) {
          if (s1 == -1) {
            s1 = s2;
            t1 = t2;
            k1 = k2;
          }
          int det = k1 * t2 - k2 * t1;
          int detx = s1 * k2 - k1 * s2;
          int dety = s1 * t2 - t1 * s2;
          if (det == 0) {
            if (detx != 0 || dety != 0) {
              cout << "-1\n";
              return 0;
            }
          } else {
            if (detx % det != 0 || dety % det != 0) {
              cout << "-1\n";
              return 0;
            }
            x = detx / det;
            y = dety / det;
            if (x <= 0 || y <= 0) {
              cout << "-1\n";
              return 0;
            }
          }
        }
      }
    }
    if (s.back() == '{') {
      ++k2;
    }
  }

  if (x != -1) {
    cout << x << "\n";
  } else if (s1 != -1) {
    if (s1 == 0 && t1 == 0) {
      cout << "-1\n";
      return 0;
    }
    for (int x = 1; x <= k1; ++x) {
      if ((s1 + t1 * x) % k1 == 0) {
        cout << x << "\n";
        return 0;
      }
    }
    cout << "-1\n";
  } else {
    cout << "1\n";
  }
  
  return 0;
}

详细

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

1

result:

ok single line: '1'

Test #3:

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

input:

4
{
ss{
ss}
}

output:

1

result:

ok single line: '1'

Test #4:

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

input:

4
{
tt{
tt}
}

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4
{
ss{
s}
}

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

4
{
tt{
t}
}

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

4
{
tt{
s}
}

output:

-1

result:

ok single line: '-1'

Test #8:

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

input:

4
{
tt{
sss}
}

output:

-1

result:

ok single line: '-1'

Test #9:

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

input:

4
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #10:

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

input:

6
{
}
{
tt{
ssss}
}

output:

2

result:

ok single line: '2'

Test #11:

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

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

input:

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

output:

20

result:

ok single line: '20'

Test #13:

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

input:

4
{
t{
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...

output:

999

result:

ok single line: '999'