QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#527333 | #7278. Brought Down the Grading Server? | skittles1412 | 0 | 41ms | 18752kb | C++17 | 4.7kb | 2024-08-22 14:18:00 | 2024-08-22 14:18:01 |
Judging History
answer
// cf bits/extc++.h nonsense
#ifdef ONLINE_JUDGE
#define _EXT_CODECVT_SPECIALIZATIONS_H 1
#define _EXT_ENC_FILEBUF_H 1
#endif
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using ll = long long;
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
inline void init_io() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
}
template <typename T>
vector<T> iota(int n, const T& x) {
vector<T> arr(n);
iota(begin(arr), end(arr), x);
return arr;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& arr) {
out << "[";
for (int i = 0; i < sz(arr); i++) {
if (i) {
out << ", ";
}
out << arr[i];
}
return out << "]";
}
template <typename T>
int c_lb(const vector<T>& arr, const T& x) {
return int(lower_bound(begin(arr), end(arr), x) - begin(arr));
}
template <typename T>
int c_ub(const vector<T>& arr, const T& x) {
return int(upper_bound(begin(arr), end(arr), x) - begin(arr));
}
template <typename T>
T reversed(T arr) {
reverse(begin(arr), end(arr));
return arr;
}
template <typename T>
T sorted(T arr) {
sort(begin(arr), end(arr));
return arr;
}
template <typename T>
bool on(T mask, int bit) {
return (mask >> bit) & 1;
}
template <typename A, typename B>
ostream& operator<<(ostream& out, const pair<A, B>& p) {
return out << "(" << p.first << ", " << p.second << ")";
}
vector<int> deg;
vector<vector<pair<int, int>>> graph;
struct Solver {
int m;
vector<bool> ans, edge_vis;
Solver(const vector<pair<int, int>>& edges)
: m(sz(edges)), ans(m), edge_vis(m) {
for (auto& [u, v] : edges) {
graph[u].clear();
graph[v].clear();
deg[u] = deg[v] = 0;
}
for (int i = 0; i < m; i++) {
auto& [u, v] = edges[i];
graph[u].emplace_back(v, i);
graph[v].emplace_back(u, ~i);
deg[u]++;
deg[v]++;
}
for (auto& [u, v] : edges) {
for (auto& ch : {u, v}) {
if (deg[ch] % 2 == 1) {
dfs(ch);
}
}
}
for (auto& [u, v] : edges) {
for (auto& ch : {u, v}) {
dfs(ch);
}
}
ans.resize(m);
}
void dfs(int u) {
while (sz(graph[u])) {
auto [v, sei] = graph[u].back();
graph[u].pop_back();
int ei = sei < 0 ? ~sei : sei;
if (edge_vis[ei]) {
continue;
}
edge_vis[ei] = true;
deg[u]--;
deg[v]--;
ans[ei] = sei < 0;
dfs(v);
break;
}
}
};
void solve(vector<vector<int>>& arr, int yl, int yr) {
if (yr - yl == 1) {
return;
}
int ym = (yl + yr) / 2;
vector<pair<int*, int*>> edge_ptrs;
vector<pair<int, int>> edges;
for (auto& a : arr) {
for (int i = 0; i < ym - yl; i++) {
int *ca = &a[yl + i], *cb = &a[ym + i];
edge_ptrs.emplace_back(ca, cb);
edges.emplace_back(*ca, *cb);
}
}
auto e_ans = Solver(edges).ans;
for (int i = 0; i < sz(e_ans); i++) {
if (e_ans[i]) {
auto& [u, v] = edge_ptrs[i];
swap(*u, *v);
}
}
solve(arr, yl, ym);
solve(arr, ym, yr);
}
void grade(const vector<vector<int>>& arr, int nt) {
int n = sz(arr), m = sz(arr[0]);
vector<vector<int>> inds(nt);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
inds[arr[i][j]].push_back(j);
}
}
for (auto& a : inds) {
int cnt[m] {};
for (auto& b : a) {
cnt[b]++;
}
assert(*max_element(cnt, cnt + m) - *min_element(cnt, cnt + m) <= 1);
}
}
void solve() {
int n, m, nt;
cin >> n >> m >> nt;
nt++;
deg.resize(nt);
graph.resize(nt);
vector arr(n, vector(m, 0));
for (auto& a : arr) {
for (auto& b : a) {
cin >> b;
}
}
solve(arr, 0, m);
for (auto& a : arr) {
for (int i = 0; i < m; i++) {
cout << a[i] + 1 << " \n"[i == m - 1];
}
}
cout.flush();
grade(arr, nt);
}
int main() {
init_io();
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
3 2 3 1 2 2 3 2 3
output:
2 3 4 3 3 4
result:
wrong answer
Subtask #2:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 41ms
memory: 18752kb
input:
100000 2 100000 70318 14894 32116 90327 63866 29061 53683 63612 70370 78264 42647 76881 39251 31741 61186 66491 57686 65819 53278 59145 71962 26052 81040 55279 50859 51310 46800 24546 85013 91165 61530 21890 84003 29099 33573 86182 49212 10639 91851 97312 57682 14067 5243 69674 99007 62508 26290 555...
output:
14895 70319 90328 32117 29062 63867 63613 53684 78265 70371 76882 42648 31742 39252 61187 66492 65820 57687 53279 59146 26053 71963 81041 55280 51311 50860 24547 46801 85014 91166 21891 61531 84004 29100 86183 33574 10640 49213 91852 97313 14068 57683 69675 5244 62509 99008 26291 55525 43795 15520 5...
result:
wrong answer
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Wrong Answer
Test #56:
score: 0
Wrong Answer
time: 0ms
memory: 3684kb
input:
3 4 3 2 3 2 2 2 3 3 2 2 2 3 2
output:
4 3 3 3 3 4 4 3 3 3 3 4
result:
wrong answer Integer parameter [name=r_j] equals to 4, violates the range [1, 3]
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #2:
0%
Subtask #9:
score: 0
Skipped
Dependency #3:
0%
Subtask #10:
score: 0
Skipped
Dependency #1:
0%