結果
| 問題 | No.100 直列あみだくじ |
| コンテスト | |
| ユーザー |
ey429
|
| 提出日時 | 2015-03-01 12:42:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 519 bytes |
| コンパイル時間 | 480 ms |
| コンパイル使用メモリ | 45,312 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 01:37:00 |
| 合計ジャッジ時間 | 1,974 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d",&nxt[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<map>
using namespace std;
int nxt[50];
bool used[50];
map<int,int> sz;
int main(){
int n,i;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&nxt[i]);
nxt[i]--;
used[i]=false;
}
for(i=0;i<n;i++)if(!used[i]){
int v=i;
int s=0;
while(!used[v]){
used[v]=true;
s++;
v=nxt[v];
}
if(s%2==0)sz[s]++;
}
for(map<int,int>::iterator it=sz.begin();it!=sz.end();it++){
pair<int,int> pr=*it;
if(pr.second%2==1){
puts("No");
return 0;
}
}
puts("Yes");
return 0;
}
ey429