Submission #19281393


Source Code Expand

Copy
#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 A[202020],B[202020];
int P[202020],RE[202020];
vector<pair<int,int>> R;
int vis[202020];


void goswap(int a,int b) {
	if(A[a]<=B[P[a]]) {
		cout<<-1<<endl;
		exit(0);
	}
	if(A[b]<=B[P[b]]) {
		cout<<-1<<endl;
		exit(0);
	}
	R.push_back({a,b});
	swap(P[a],P[b]);
	RE[P[a]]=a;
	RE[P[b]]=b;
}

void hoge(vector<int> V) {
	vector<pair<int,int>> cand;
	FORR(v,V) cand.push_back({B[v],v});
	sort(ALL(cand));
	reverse(ALL(cand));
	FORR(c,cand) {
		int tar=c.second;
		if(RE[tar]==tar) continue;
		
		goswap(RE[tar],tar);
	}
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i];
	FOR(i,N) cin>>B[i];
	FOR(i,N) {
		cin>>P[i];
		P[i]--;
		RE[P[i]]=i;
	}
	FOR(i,N) if(vis[i]==0) {
		vector<int> V;
		V.push_back(i);
		x=P[i];
		while(x!=i) {
			V.push_back(x);
			x=P[x];
		}
		hoge(V);
	}
	
	cout<<R.size()<<endl;
	FORR(r,R) cout<<r.first+1<<" "<<r.second+1<<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;
}

Submission Info

Submission Time
Task C - Too Heavy
User kmjp
Language C++ (GCC 9.2.1)
Score 600
Code Size 1790 Byte
Status AC
Exec Time 381 ms
Memory 12564 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:54:8: warning: unused variable ‘j’ [-Wunused-variable]
   54 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:54:10: warning: unused variable ‘k’ [-Wunused-variable]
   54 |  int i,j,k,l,r,x,y; string s;
      |          ^
./Main.cpp:54:12: warning: unused variable ‘l’ [-Wunused-variable]
   54 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp:54:14: warning: unused variable ‘r’ [-Wunused-variable]
   54 |  int i,j,k,l,r,x,y; string s;
      |              ^
./Main.cpp:54:18: warning: unused variable ‘y’ [-Wunused-variable]
   54 |  int i,j,k,l,r,x,y; string s;
      |                  ^
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
./Main.cpp:85:38: note: in expansion of macro ‘FOR’
   85 |  FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                      ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 47
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt
Case Name Status Exec Time Memory
0_000.txt AC 14 ms 3624 KB
0_001.txt AC 2 ms 3632 KB
0_002.txt AC 2 ms 3592 KB
1_003.txt AC 2 ms 3660 KB
1_004.txt AC 2 ms 3632 KB
1_005.txt AC 3 ms 3528 KB
1_006.txt AC 2 ms 3632 KB
1_007.txt AC 2 ms 3536 KB
1_008.txt AC 2 ms 3588 KB
1_009.txt AC 2 ms 3660 KB
1_010.txt AC 2 ms 3516 KB
1_011.txt AC 61 ms 6772 KB
1_012.txt AC 65 ms 8100 KB
1_013.txt AC 72 ms 8568 KB
1_014.txt AC 3 ms 3624 KB
1_015.txt AC 6 ms 3584 KB
1_016.txt AC 2 ms 3532 KB
1_017.txt AC 3 ms 3596 KB
1_018.txt AC 4 ms 3624 KB
1_019.txt AC 3 ms 3588 KB
1_020.txt AC 2 ms 3476 KB
1_021.txt AC 2 ms 3588 KB
1_022.txt AC 3 ms 3600 KB
1_023.txt AC 3 ms 3624 KB
1_024.txt AC 2 ms 3664 KB
1_025.txt AC 8 ms 3604 KB
1_026.txt AC 2 ms 3592 KB
1_027.txt AC 3 ms 3536 KB
1_028.txt AC 4 ms 3592 KB
1_029.txt AC 376 ms 10716 KB
1_030.txt AC 372 ms 10288 KB
1_031.txt AC 369 ms 10792 KB
1_032.txt AC 375 ms 9756 KB
1_033.txt AC 373 ms 11716 KB
1_034.txt AC 369 ms 10748 KB
1_035.txt AC 376 ms 11916 KB
1_036.txt AC 368 ms 11792 KB
1_037.txt AC 381 ms 12060 KB
1_038.txt AC 369 ms 9872 KB
1_039.txt AC 67 ms 6648 KB
1_040.txt AC 378 ms 12508 KB
1_041.txt AC 369 ms 12484 KB
1_042.txt AC 224 ms 7332 KB
1_043.txt AC 68 ms 6792 KB
1_044.txt AC 374 ms 12504 KB
1_045.txt AC 374 ms 12564 KB
1_046.txt AC 219 ms 7380 KB