QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#730000 | #6568. Space Alignment | ahsoltan# | WA | 97ms | 3848kb | C++20 | 3.5kb | 2024-11-09 18:15:00 | 2024-11-09 18:15:00 |
Judging History
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;
M[dep].insert({tab, spa});
if(delta == +1)
++dep;
}
debug(M);
for(ll cze = 1; cze <= 5'000'000; cze++) {
bool ok = 1;
vector<ll> wyn(sz(M), -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;
}
if(wyn[0] != 0 && wyn[0] != -1)
continue;
debug(ok);
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: 3848kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 97ms
memory: 3616kb
input:
2 { }
output:
-1
result:
wrong answer 1st lines differ - expected: '1', found: '-1'