結果

問題 No.1913 Periodic Comparison
ユーザー 👑 kmjpkmjp
提出日時 2022-05-25 00:30:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,664 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 208,176 KB
実行使用メモリ 15,548 KB
最終ジャッジ日時 2023-10-20 19:02:58
合計ジャッジ時間 9,160 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
14,548 KB
testcase_01 AC 4 ms
14,544 KB
testcase_02 AC 8 ms
14,548 KB
testcase_03 AC 5 ms
14,548 KB
testcase_04 AC 5 ms
14,548 KB
testcase_05 AC 5 ms
14,548 KB
testcase_06 AC 5 ms
14,548 KB
testcase_07 AC 4 ms
14,548 KB
testcase_08 AC 16 ms
14,596 KB
testcase_09 AC 71 ms
15,424 KB
testcase_10 AC 15 ms
14,584 KB
testcase_11 AC 68 ms
15,220 KB
testcase_12 AC 44 ms
15,536 KB
testcase_13 AC 12 ms
14,568 KB
testcase_14 AC 58 ms
15,528 KB
testcase_15 AC 71 ms
15,016 KB
testcase_16 AC 57 ms
15,540 KB
testcase_17 AC 15 ms
14,592 KB
testcase_18 AC 13 ms
14,572 KB
testcase_19 AC 67 ms
15,256 KB
testcase_20 AC 49 ms
15,076 KB
testcase_21 AC 69 ms
15,320 KB
testcase_22 AC 14 ms
14,568 KB
testcase_23 AC 11 ms
14,560 KB
testcase_24 AC 75 ms
15,192 KB
testcase_25 AC 47 ms
15,536 KB
testcase_26 AC 59 ms
15,540 KB
testcase_27 AC 15 ms
14,576 KB
testcase_28 AC 17 ms
14,588 KB
testcase_29 AC 71 ms
15,548 KB
testcase_30 AC 58 ms
15,476 KB
testcase_31 AC 12 ms
14,560 KB
testcase_32 AC 13 ms
14,564 KB
testcase_33 AC 14 ms
14,572 KB
testcase_34 AC 69 ms
15,288 KB
testcase_35 AC 76 ms
15,300 KB
testcase_36 AC 45 ms
15,536 KB
testcase_37 AC 73 ms
15,068 KB
testcase_38 AC 5 ms
14,548 KB
testcase_39 AC 5 ms
14,544 KB
testcase_40 AC 63 ms
15,396 KB
testcase_41 AC 63 ms
15,260 KB
testcase_42 AC 62 ms
15,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


int N;
int X[202020],Y[202020];

int F[202020];
int R[202020];
int rev[2020202];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	MINUS(rev);
	cin>>N;
	int M=0;
	FOR(i,N) cin>>X[i];
	FOR(i,N) {
		cin>>Y[i];
		
		if(rev[Y[i]]!=-1) {
			cout<<-1<<endl;
			return;
		}
		rev[Y[i]]=i;
		
		M=max({M,X[i],Y[i]});
		
		
		
	}
	queue<int> Q;
	MINUS(R);
	FOR(i,N) Q.push(i);
	for(i=M;i>=0;i--) {
		if(Q.empty()) {
			cout<<-1<<endl;
			return;
		}
			
		x=Q.front();
		Q.pop();
		if(rev[i]>=0) {
			if(R[x]!=-1) {
				cout<<-1<<endl;
				return;
			}
			R[x]=rev[i];
			if(X[R[x]]>0) {
				Q.push(x);
			}
			F[R[x]]=i;
			X[R[x]]--;
		}
		else {
			if(R[x]!=-1) {
				if(X[R[x]]>0) {
					Q.push(x);
				}
				F[R[x]]=i;
				X[R[x]]--;
			}
			else {
				Q.push(x);
			}
		}
	}
	if(Q.size()) {
		cout<<-1<<endl;
		return;
	}
	FOR(i,N) cout<<F[i]<<" ";
	cout<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0