QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#286451 | #1965. Trio | warner1129 | WA | 0ms | 3864kb | C++20 | 3.3kb | 2023-12-17 21:38:42 | 2023-12-17 21:38:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template <class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template <class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<int, int>;
template <class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
constexpr double eps = 0;
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
const int kN = 10000 + 5;
int cnt[kN]{};
void solve() {
int n;
cin >> n;
vector<string> S(n);
for (auto &s : S) {
cin >> s;
}
i64 ans = 0;
for (int e = 0; e < (1 << 4) - 1; e++) {
vector<pair<string, string>> E(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 4; j++)
if (e >> j & 1) {
E[i].ff += S[i][j];
} else {
E[i].ss += S[i][j];
}
}
sort(all(E));
int len = E[0].ss.size();
vector<vector<pair<int, int>>> F(n);
for (int i = 0; i < n; i++) {
auto rec = [&](auto self, int val, int k, int f) -> void {
if (k == len) {
F[i].emplace_back(val, f % 2 == 1 ? -1 : 1);
return;
}
self(self, val * 10 + E[i].ss[k] - '0', k + 1, f + 1);
self(self, val * 10, k + 1, f + 1);
};
rec(rec, 0, 0, 0);
}
for (int l = 0, r = 0; l < n; l = r) {
while (r < n and E[r].ff == E[l].ff) r++;
debug(bitset<4>(e), l, r);
for (int i = l + 2; i < r; i++) {
// debug(i, E[i].ff, E[i].ss);
vector<int> del;
for (int j = l; j < i; j++) {
bool dif = true;
for (int k = 0; k < len; k++)
if (E[j].ss[k] == E[i].ss[k]) {
dif = false;
break;
}
// debug(j, E[j].ff, E[j].ss);
if (!dif) continue;
del.push_back(j);
for (auto [s, v] : F[j]) {
ans += cnt[s] * v;
cnt[s]++;
}
}
for (int j : del) for (auto [s, _] : F[j]) {
cnt[s] = 0;
}
}
}
}
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3864kb
input:
4 1234 2345 3456 4567
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
9 1299 2399 3499 4599 5699 6799 7899 8999 9199
output:
84
result:
ok single line: '84'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
9 1239 2349 3459 4569 5679 6789 7899 8919 9129
output:
-84
result:
wrong answer 1st lines differ - expected: '84', found: '-84'