QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#729944#6568. Space Alignmentahsoltan#WA 1ms3596kbC++203.4kb2024-11-09 18:05:172024-11-09 18:05:18

Judging History

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

  • [2024-11-09 18:05:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3596kb
  • [2024-11-09 18:05:17]
  • 提交

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;
  map<int, set<pair<ll, ll>>> M;
  int dep = 0;
  rep(_, 0, n) {
    string s;
    cin >> s;
    ll spa = 0;
    ll tab = 0;
    for(auto i : s) {
      if(i == 's')
        ++spa;
      else if(i == 't')
        ++tab;
    }
    int delta = s[sz(s) - 1] == '{' ? 1 : -1;
    debug(_, dep, s, tab, spa);
    if(delta == -1)
      --dep;
    if(dep)
      M[dep].insert({tab, spa});
    if(delta == +1)
      ++dep;
  }



  for(ll cze = 1; cze <= 6969; cze++) {
    bool ok = 1;
    vector<ll> wyn(sz(M) + 1, -1);
    for(auto &[ki, ko] : M) {
      for(auto [tab, spa] : ko) {
        ll got = tab * cze + spa;
        if(wyn[ki] == -1) {
          wyn[ki] = got;
          continue;
        }
        if(wyn[ki] != got) {
          ok = 0;
          break;
        }
      }
      if(!ok)
        break;
    }
    ll mn = 1e18, mx = -1;
    for(int i = 1; i < sz(wyn); i++) {
      if(wyn[i] % i != 0) {
        ok = 0;
        break;
      }
      ll got = wyn[i] / i;
      mn = min(mn, got);
      mx = max(mx, got);
    }
    if(mn != mx) {
      ok = 0;
    }
    if(ok) {
      cout << cze << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  // debug(M);
  // ll found = 1;
  // bool jest = false;
  // for(auto [ki, kon] : M) {
  //   if(sz(kon) <= 1)
  //     continue;
  //   auto x = *kon.begin();
  //   kon.erase(x);
  //   auto y = *kon.begin();
  //   debug(ki, x, y);
  //   if(x.first == y.first) {
  //     found = -1;
  //     break;
  //   }
  //   ll fir = x.first - y.first;
  //   ll sek = y.second - x.second;
  //   if(fir == 0 || sek == 0 || (sek / fir) * fir != sek) {
  //     found = -1;
  //     break;
  //   }
  //   found = sek / fir;
  //   jest = true;
  //   break;
  // }

  // debug(found);

  // if(found == -1) {
  //   cout << -1 << endl;
  //   exit(0);
  // }



  // if(jest) {
  //   ll mng = 1e18, mxg = -1;
  //   for(auto [ki, kon] : M) {
  //     ll mn = 1e18, mx = -1;
  //     for(auto [tab, spa] : kon) {
  //       ll got = tab * found + spa;
  //       mn = min(mn, got);
  //       mx = max(mx, got);
  //     }
  //     if(mn != mx) {
  //       found = -1;
  //       break;
  //     }
  //     if(mn % ki != 0) {
  //       found = -1;
  //       break;
  //     }
  //     ll of = mn / ki;
  //     mng = min(mng, of);
  //     mxg = max(mxg, of);
  //   }
  //   if(mng != mxg)
  //     found = -1;
  //   cout << found << endl;
  //   return 0;
  // }
  // debug(found);


  // if(found <= 0) {
  //   cout << -1 << endl;
  //   exit(0);
  // }

  // cout << found << endl;

  
}

詳細信息

Test #1:

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

input:

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

output:

2

result:

ok single line: '2'

Test #2:

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

input:

2
{
}

output:

-1

result:

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