답안 #81142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
81142 2018-10-24T02:25:54 Z FutymyClone Baloni (COCI15_baloni) C++14
0 / 100
128 ms 8532 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

struct disj {
    int par[N];
    void init (int n) {
        for (int i = 1; i <= n; i++) par[i] = i;
    }

    int Find (int x) {
        return par[x] == x ? x : par[x] = Find(par[x]);
    }

    void join (int x, int y) {
        x = Find(x); y = Find(y);
        if (x == y) return;
        par[y] = x;
    }
} dsu;

int n, a[N], last[N];
bool used[N];

int main(){
    scanf("%d", &n); dsu.init(n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) {
        if (last[a[i] + 1] && !used[last[a[i] + 1]]) dsu.join(i, last[a[i] + 1]), used[last[a[i] + 1]] = true;
        last[a[i]] = i;
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) ans += dsu.par[i] == i;
    printf("%d", ans);
    return 0;
}

Compilation message

baloni.cpp: In function 'int main()':
baloni.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n); dsu.init(n);
     ~~~~~^~~~~~~~~~
baloni.cpp:29:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
                                  ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 600 KB Output isn't correct
3 Incorrect 3 ms 600 KB Output isn't correct
4 Incorrect 3 ms 600 KB Output isn't correct
5 Incorrect 115 ms 7460 KB Output isn't correct
6 Incorrect 128 ms 8532 KB Output isn't correct
7 Incorrect 114 ms 8532 KB Output isn't correct
8 Incorrect 101 ms 8532 KB Output isn't correct
9 Incorrect 115 ms 8532 KB Output isn't correct
10 Incorrect 114 ms 8532 KB Output isn't correct