Submission #69714484
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
/////////////////// メイン ///////////////////
int main () {
//////////////////// 入力 ////////////////////
int n;
cin >> n;
vector<int> a(n);
for (int i=0; i<n; i++) {
cin >> a.at(i);
}
//////////////// 出力変数定義 ////////////////
bool result = true;
// vectorの方はaをそのまま使う
//////////////////// 処理 ////////////////////
// -1以外に何が何個あるかカウントしつつ、-1の場所を記録する
vector<int> count(n+1,0);
vector<int> blank;
for (int i=0; i<n; i++) {
if (a.at(i)==-1) blank.emplace_back(i);
else {
count.at(a.at(i))++;
}
}
// 1つも登場してない数をカウント
vector<int> absence;
for (int i=1; i<=n; i++) {
if (count.at(i)==0) absence.emplace_back(i);
}
// -1のところに、未使用の数を順番に入れる(未使用の数の個数は空白の個数以上にあるはず)
// 入れたら、countを更新
for (size_t i=0; i<blank.size(); i++) {
a.at(blank.at(i)) = absence.at(i);
count.at(absence.at(i))++;
}
// カウントが0じゃないところがあったら、falseにする
for (int i=1; i<=n; i++) {
if (count.at(i)!=1) result = false;
}
//////////////////// 出力 ////////////////////
if (result) {
cout << "Yes" << endl;
for (size_t i=0; i<a.size(); i++) {
cout << a.at(i);
if (i!=a.size()-1) {
cout << " ";
}
}
cout << endl;
} else {
cout << "No" << endl;
}
//////////////////// 終了 ////////////////////
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Find Permutation 2 |
| User | wightou |
| Language | C++ 23 (gcc 12.2) |
| Score | 200 |
| Code Size | 1701 Byte |
| Status | AC |
| Exec Time | 1 ms |
| Memory | 3660 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_Yes_00.txt, 01_Yes_01.txt, 01_Yes_02.txt, 01_Yes_03.txt, 01_Yes_04.txt, 01_Yes_05.txt, 01_Yes_06.txt, 01_Yes_07.txt, 01_Yes_08.txt, 01_Yes_09.txt, 01_Yes_10.txt, 01_Yes_11.txt, 01_Yes_12.txt, 01_Yes_13.txt, 01_Yes_14.txt, 01_Yes_15.txt, 01_Yes_16.txt, 01_Yes_17.txt, 01_Yes_18.txt, 01_Yes_19.txt, 01_Yes_20.txt, 02_No_00.txt, 02_No_01.txt, 02_No_02.txt, 02_No_03.txt, 02_No_04.txt, 02_No_05.txt, 02_No_06.txt, 02_No_07.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3428 KiB |
| 00_sample_01.txt | AC | 1 ms | 3456 KiB |
| 00_sample_02.txt | AC | 1 ms | 3452 KiB |
| 01_Yes_00.txt | AC | 1 ms | 3432 KiB |
| 01_Yes_01.txt | AC | 1 ms | 3496 KiB |
| 01_Yes_02.txt | AC | 1 ms | 3500 KiB |
| 01_Yes_03.txt | AC | 1 ms | 3572 KiB |
| 01_Yes_04.txt | AC | 1 ms | 3500 KiB |
| 01_Yes_05.txt | AC | 1 ms | 3500 KiB |
| 01_Yes_06.txt | AC | 1 ms | 3472 KiB |
| 01_Yes_07.txt | AC | 1 ms | 3660 KiB |
| 01_Yes_08.txt | AC | 1 ms | 3652 KiB |
| 01_Yes_09.txt | AC | 1 ms | 3492 KiB |
| 01_Yes_10.txt | AC | 1 ms | 3500 KiB |
| 01_Yes_11.txt | AC | 1 ms | 3460 KiB |
| 01_Yes_12.txt | AC | 1 ms | 3568 KiB |
| 01_Yes_13.txt | AC | 1 ms | 3456 KiB |
| 01_Yes_14.txt | AC | 1 ms | 3504 KiB |
| 01_Yes_15.txt | AC | 1 ms | 3540 KiB |
| 01_Yes_16.txt | AC | 1 ms | 3572 KiB |
| 01_Yes_17.txt | AC | 1 ms | 3448 KiB |
| 01_Yes_18.txt | AC | 1 ms | 3496 KiB |
| 01_Yes_19.txt | AC | 1 ms | 3488 KiB |
| 01_Yes_20.txt | AC | 1 ms | 3464 KiB |
| 02_No_00.txt | AC | 1 ms | 3460 KiB |
| 02_No_01.txt | AC | 1 ms | 3448 KiB |
| 02_No_02.txt | AC | 1 ms | 3452 KiB |
| 02_No_03.txt | AC | 1 ms | 3460 KiB |
| 02_No_04.txt | AC | 1 ms | 3468 KiB |
| 02_No_05.txt | AC | 1 ms | 3652 KiB |
| 02_No_06.txt | AC | 1 ms | 3656 KiB |
| 02_No_07.txt | AC | 1 ms | 3536 KiB |