| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1338724 | vuviet | Pictionary (COCI18_pictionary) | C++20 | 112 ms | 6668 KiB |
/**
* Author: trviet
* Studies at: Le Hong Phong High School for the Gifted
**/
#include <bits/stdc++.h>
#define ____vuviet__ signed main
#define taskname "trviet"
using namespace std;
constexpr int N = 1e5 + 5;
int n, m, q, lo[N], hi[N], res[N], a[N], b[N];
struct DisjointSets
{
int sz;
vector<int> lab;
DisjointSets(int sz)
{
this->sz = sz;
lab.resize(sz + 1, -1);
}
int findset(int u)
{
return lab[u] < 0 ? u : lab[u] = findset(lab[u]);
}
void unite(int r, int s)
{
r = findset(r), s = findset(s);
if (r == s) return;
if (lab[r] > lab[s]) swap(r, s);
lab[r] += lab[s], lab[s] = r;
}
};
void ReadData()
{
cin >> n >> m >> q;
for (int i = 1; i <= q; ++i)
{
cin >> a[i] >> b[i];
lo[i] = 1, hi[i] = m;
}
}
int lg2(int x)
{
int cnt = 0;
while (x > 0)
++cnt, x /= 2;
return cnt - 1;
}
void solvebytrvietbels()
{
ReadData();
int log2 = lg2(m + 1);
for (int t = 0; t < log2 + 1; ++t)
{
vector<vector<int>> queries(m + 1);
for (int i = 1; i <= q; ++i)
if (lo[i] <= hi[i])
queries[(lo[i] + hi[i]) / 2].push_back(i);
DisjointSets dsu(n + 5);
for (int g = m; g >= 1; --g)
{
for (int k = g * 2; k <= n; k += g)
dsu.unite(g, k);
for (int id : queries[g])
{
if (dsu.findset(a[id]) == dsu.findset(b[id])) {
res[id] = g, lo[id] = g + 1;
} else {
hi[id] = g - 1;
}
}
}
}
for (int i = 1; i <= q; ++i)
{
int days = m - res[i] + 1;
cout << days << "\n";
}
}
void freopen_stdio(string speech)
{
cin.tie(0)->sync_with_stdio(0);
cerr << speech << "\n";
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
}
____vuviet__()
{
freopen_stdio("...miss you...");
int t = 1;
// cin >> t;
while (t-- > 0)
solvebytrvietbels();
return 0;
}컴파일 시 표준 에러 (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... | ||||
