# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
347763 | Markomafko972 | Pictionary (COCI18_pictionary) | C++14 | 523 ms | 12080 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n, m, q;
pii p[100005];
vector< pair<pii, int> > gdje[100005];
vector< pair<pii, int> > slj[100005];
int sol[100005];
int prt[100005];
int find(int x) {
if (prt[x] == x) return x;
return prt[x] = find(prt[x]);
}
void unija(int x, int y) {
x = find(x);
y = find(y);
if (x != y) {
prt[x] = y;
}
}
int main () {
cin >> n >> m >> q;
for (int i = 0; i < q; i++) {
cin >> p[i].X >> p[i].Y;
gdje[(1+m)/2].push_back({{1, m}, i});
}
int kol = q;
while (kol > 0) {
for (int i = 1; i <= n; i++) prt[i] = i;
for (int i = 1; i <= m; i++) {
for (int j = 2*(m-i+1); j <= n; j += m-i+1) {
unija(m-i+1, j);
}
for (int j = 0; j < gdje[i].size(); j++) {
int p1 = find(p[gdje[i][j].Y].X);
int p2 = find(p[gdje[i][j].Y].Y);
if (p1 == p2) {
if (gdje[i][j].X.X == gdje[i][j].X.Y) {
sol[gdje[i][j].Y] = i;
kol--;
}
else slj[(gdje[i][j].X.X+i)/2].push_back({{gdje[i][j].X.X, i}, gdje[i][j].Y});
}
else {
slj[(i+1+gdje[i][j].X.Y)/2].push_back({{i+1, gdje[i][j].X.Y}, gdje[i][j].Y});
}
}
}
for (int i = 1; i <= m; i++) {
gdje[i].clear();
gdje[i].shrink_to_fit();
gdje[i] = slj[i];
slj[i].clear();
slj[i].shrink_to_fit();
}
}
for (int i = 0; i < q; i++) cout << sol[i] << "\n";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |