QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#729424 | #6568. Space Alignment | ahsoltan# | WA | 0ms | 3840kb | C++20 | 3.4kb | 2024-11-09 17:05:46 | 2024-11-09 17:05:48 |
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(dep && delta == 1)
M[dep].insert({tab, spa});
dep += delta;
}
for(int cze = 1; cze <= 5000; 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] == -1)
continue;
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: 3600kb
input:
10 { ss{ sts{ tt} t} t{ ss} } { }
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3840kb
input:
2 { }
output:
-1
result:
wrong answer 1st lines differ - expected: '1', found: '-1'