結果
| 問題 | 
                            No.1373 Directed Operations
                             | 
                    
| コンテスト | |
| ユーザー | 
                             leaf_1415
                         | 
                    
| 提出日時 | 2020-10-09 03:44:00 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 766 bytes | 
| コンパイル時間 | 569 ms | 
| コンパイル使用メモリ | 63,616 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-20 19:07:35 | 
| 合計ジャッジ時間 | 4,026 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 14 WA * 5 | 
ソースコード
#include <iostream>
#include <cassert>
#include <vector>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;
typedef pair<int, int> P;
int n;
int a[100005];
P p[100005];
int ans[100005];
int main()
{
	cin >> n;
	assert(n >= 2 && n <= 100000);
	for(int i = 1; i <= n-1; i++){
		cin >> a[i];
		assert(a[i] >= 1 && a[i] <= n-1);
	}
	
	for(int i = 1; i <= n-1; i++) p[i] = P(a[i], i);
	sort(p+1, p+n);
	
	for(int i = 1; i <= n-1; i++){
		if(p[i].first > i){
			cout << "NO" << endl;
			return 0;
		}
		ans[p[i].second] = (i+1) - a[p[i].second];
	}
	
	srand(time(NULL));
	int x = rand() % (n-1) + 1, y = rand() % (n-1) + 1;
	swap(ans[x], ans[y]);
	
	cout << "YES" << endl;
	for(int i = 1; i <= n-1; i++) cout << ans[i] << endl;
	
	return 0;
}
            
            
            
        
            
leaf_1415