답안 #1033131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033131 2024-07-24T13:11:11 Z Zicrus 식물 비교 (IOI20_plants) C++17
0 / 100
4000 ms 6648 KB
#include <bits/stdc++.h>
#include "plants.h"
using namespace std;

typedef long long ll;

vector<ll> lnk;
vector<int> a;

ll find(ll a) {
    if (lnk[a] != a) lnk[a] = find(lnk[a]);
    return lnk[a];
}

void unite(ll a, ll b) {
    a = find(a); b = find(b);
    lnk[b] = a;
}

bool same(ll a, ll b) {
    return find(a) == find(b);
}

void init(int k, vector<int> r) {
    ll n = r.size();
    lnk = vector<ll>(n);
    for (int i = 0; i < n; i++) lnk[i] = i;
    for (int i = n-1; i >= 0; i--) {
        int o = (i+1) % n;
        if (r[i] == r[o]) unite(i, o);
    }
    a = vector<int>(n);
    for (int i = 0; i < n; i++) a[i] = r[i];
}

int compare_plants(int x, int y) {
    ll n = a.size();

    ll dir = a[x];
    for (int i = x; i != y; i++) {
        if (dir != a[i]) break;
        if (i == y-1) {
            //return dir == 1 ? -1 : 1;
            break;
        }
    }
    dir = a[y];
    for (int i = y; i != x; i = (i+1)%n) {
        if (dir != a[i]) break;
        if (i == (x-1+n)%n) {
            return dir == 0 ? -1 : 1;
        }
    }

    if (same(x, (y-1+n)%n)) {
         return (a[x] ? -1 : 1);
    }
    if (same((x-1+n)%n, y)) {
        return (!a[y] ? -1 : 1);
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 34 ms 3056 KB Output is correct
7 Correct 132 ms 3428 KB Output is correct
8 Correct 63 ms 6480 KB Output is correct
9 Correct 141 ms 6484 KB Output is correct
10 Correct 809 ms 6484 KB Output is correct
11 Execution timed out 4059 ms 6648 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 344 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 34 ms 3056 KB Output is correct
7 Correct 132 ms 3428 KB Output is correct
8 Correct 63 ms 6480 KB Output is correct
9 Correct 141 ms 6484 KB Output is correct
10 Correct 809 ms 6484 KB Output is correct
11 Execution timed out 4059 ms 6648 KB Time limit exceeded
12 Halted 0 ms 0 KB -