結果
| 問題 | No.482 あなたの名は |
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-07-29 13:51:16 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,290 bytes |
| 記録 | |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 30,464 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 15:18:22 |
| 合計ジャッジ時間 | 1,387 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.c: In function 'in':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
10 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:18:24: note: in expansion of macro 'gc'
18 | int n = 0, c = gc();
| ^~
main.c: In function 'outs':
main.c:11:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
11 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:29:33: note: in expansion of macro 'pc'
29 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
| ^~
ソースコード
// yukicoder: No.482 あなたの名は
// 2019.7.29 bal4u
#include <stdio.h>
#include <string.h>
typedef long long ll;
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() { // 非負整数の入力
int n = 0, c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
ll In() { // 非負整数の入力
ll n = 0; int c = gc();
do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
return n;
}
void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
/* UNION-FIND library */
#define MAX 200003
int uni[MAX];
void init(int n) { memset(uni, -1, sizeof(int)*n); }
int root(int i) {
if (uni[i] < 0) return i;
return uni[i] = root(uni[i]);
}
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q) {
int t; p = root(p), q = root(q); if (p == q) return;
if (uni[p] > uni[q]) t = p, p = q, q = t;
uni[p] += uni[q], uni[q] = p;
}
int size(int i) { return -uni[root(i)]; }
int N; ll K;
int main()
{
int i, ans;
N = in(), K = In(), init(N+1);
for (i = 1; i <= N; i++) unite(in(), i);
ans = 0; for (i = 1; i <= N; i++) if (root(i) == i && uni[i] < -1) ans += -uni[i]-1;
outs(ans <= K && ((K - ans) & 1) == 0? "YES": "NO");
return 0;
}
bal4u