結果

問題 No.482 あなたの名は
ユーザー bal4ubal4u
提出日時 2019-07-29 13:51:16
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,290 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 30,036 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-15 11:50:37
合計ジャッジ時間 1,810 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 0 ms
4,388 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 0 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 0 ms
4,380 KB
testcase_15 AC 9 ms
4,380 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 9 ms
4,380 KB
testcase_19 AC 9 ms
4,376 KB
testcase_20 AC 9 ms
4,384 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 9 ms
4,380 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 9 ms
4,380 KB
testcase_26 AC 9 ms
4,380 KB
testcase_27 AC 9 ms
4,380 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 6 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:10:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:18:24: 備考: in expansion of macro ‘gc’
   18 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘outs’ 内:
main.c:11:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:29:33: 備考: in expansion of macro ‘pc’
   29 | void outs(char *s) { while (*s) pc(*s++); pc('\n'); }
      |                                 ^~

ソースコード

diff #

// 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;
}
0