답안 #854674

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854674 2023-09-28T12:57:31 Z hariaakas646 Pictionary (COCI18_pictionary) C++17
140 / 140
1037 ms 10016 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;

void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

vi disset;
vector<vii> graph;

int findf(int x) {
    while(x != disset[x]) x = disset[x];
    return x;
}

void unionf(int x, int y) {
    int x2 = findf(x);
    int y2 = findf(y);
    disset[x2] = y2;
}

vii par;
vi depth;

void dfs(int x, int p, int d, int v) {
    par[x] = mp(p, v);
    depth[x] = d;
    for(auto e : graph[x]) {
        if(e.f != p) dfs(e.f, x, d+1, e.s);
    }
}

int main() {
    // usaco();
    int n, m, q;
    scd(n);
    scd(m);
    scd(q);

    graph = vector<vii>(n+1);
    disset = vi(n+1);

    frange(i, n+1) disset[i] = i;
    
    frange(i, m) {
        int v = m - i;
        for(int j=2*v; j<=n; j+=v) {
            if(findf(j) != findf(v)) {
                unionf(j, v);
                graph[j].pb(mp(v, i+1));
                graph[v].pb(mp(j, i+1));
            }
        }
    }

    depth = vi(n+1);
    par = vii(n+1);
    dfs(1, 0, 0, 0);
    frange(i, q) {
        int a, b;
        scd(a);
        scd(b);
        int ma = 0;
        if(depth[a] > depth[b]) swap(a, b);
        while(depth[b] > depth[a]) {
            ma = max(ma, par[b].s);
            b = par[b].f;
        }
        while(a != b) {
            ma = max(ma, par[b].s);
            ma = max(ma, par[a].s);
            a = par[a].f;
            b = par[b].f;
        }
        printf("%d\n", ma);

    }
}

Compilation message

pictionary.cpp: In function 'void usaco()':
pictionary.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pictionary.cpp: In function 'int main()':
pictionary.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pictionary.cpp:61:5: note: in expansion of macro 'scd'
   61 |     scd(n);
      |     ^~~
pictionary.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pictionary.cpp:62:5: note: in expansion of macro 'scd'
   62 |     scd(m);
      |     ^~~
pictionary.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pictionary.cpp:63:5: note: in expansion of macro 'scd'
   63 |     scd(q);
      |     ^~~
pictionary.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pictionary.cpp:86:9: note: in expansion of macro 'scd'
   86 |         scd(a);
      |         ^~~
pictionary.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
pictionary.cpp:87:9: note: in expansion of macro 'scd'
   87 |         scd(b);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1116 KB Output is correct
2 Correct 19 ms 1240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 1544 KB Output is correct
2 Correct 28 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 3160 KB Output is correct
2 Correct 95 ms 2812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 3412 KB Output is correct
2 Correct 139 ms 3908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 289 ms 5040 KB Output is correct
2 Correct 309 ms 4968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 6740 KB Output is correct
2 Correct 573 ms 7136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 695 ms 7728 KB Output is correct
2 Correct 835 ms 8996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1037 ms 9960 KB Output is correct
2 Correct 1022 ms 10016 KB Output is correct