Submission #48398782


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define int long long
int inversions(vector<int> &arr) {
multiset<int> set1;
set1.insert(arr[0]);
int invcount = 0;
multiset<int>::iterator itset1;
for (int i=1; i<arr.size(); i++) {
set1.insert(arr[i]);
itset1 = set1.upper_bound(arr[i]);
invcount += distance(itset1, set1.end());
}
return invcount;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, m; cin >> n >> m;
set<int> a[n], b[n], c[m], d[m];
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;
#define int long long

int inversions(vector<int> &arr) { 
    multiset<int> set1; 
    set1.insert(arr[0]); 
    int invcount = 0;
    multiset<int>::iterator itset1;
    for (int i=1; i<arr.size(); i++) { 
        set1.insert(arr[i]); 
        itset1 = set1.upper_bound(arr[i]); 
        invcount += distance(itset1, set1.end()); 
    } 
    return invcount; 
} 

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n, m; cin >> n >> m;
	set<int> a[n], b[n], c[m], d[m];
	multiset<int> aa, bb;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int x; cin >> x;
			a[i].insert(x);
			c[j].insert(x);
			aa.insert(x);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int x; cin >> x;
			b[i].insert(x);
			d[j].insert(x);
			bb.insert(x);
		}
	}
	
	bool b1 = false; bool used1[n]{}; vector<int> v1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (!used1[j] && b[i] == a[j]) {
				v1.push_back(j);
				used1[j] = 1;
				b1 = true;
				break;
			}
		}
	}
	
	bool b2 = true; bool used2[n]{}; vector<int> v2;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			if (d[i] == c[j]) {
				v2.push_back(j);
				used2[j] = 1;
				b2 = true;
				break;
			}
		}
	}
	
	int ans = inversions(v1) + inversions(v2);
	
	if (!b1 || !b2 || aa != bb) cout << -1;
	else cout << ans;
}

Submission Info

Submission Time
Task D - Swapping Puzzle
User ThePwo
Language C++ 20 (gcc 12.2)
Score 0
Code Size 1485 Byte
Status RE
Exec Time 329 ms
Memory 3644 KB

Compile Error

Main.cpp: In function ‘long long int inversions(std::vector<long long int>&)’:
Main.cpp:10:20: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   10 |     for (int i=1; i<arr.size(); i++) {
      |                   ~^~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 425
Status
AC × 4
AC × 22
WA × 15
RE × 5
Set Name Test Cases
Sample example0.txt, example1.txt, example2.txt, example3.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, example0.txt, example1.txt, example2.txt, example3.txt
Case Name Status Exec Time Memory
000.txt WA 1 ms 3496 KB
001.txt RE 329 ms 3120 KB
002.txt WA 1 ms 3644 KB
003.txt RE 74 ms 3172 KB
004.txt RE 73 ms 3152 KB
005.txt RE 74 ms 3360 KB
006.txt AC 1 ms 3512 KB
007.txt AC 1 ms 3508 KB
008.txt AC 1 ms 3508 KB
009.txt AC 1 ms 3404 KB
010.txt WA 1 ms 3420 KB
011.txt WA 1 ms 3412 KB
012.txt WA 1 ms 3516 KB
013.txt AC 1 ms 3508 KB
014.txt AC 1 ms 3440 KB
015.txt AC 1 ms 3516 KB
016.txt AC 1 ms 3524 KB
017.txt AC 1 ms 3508 KB
018.txt AC 1 ms 3600 KB
019.txt AC 1 ms 3636 KB
020.txt AC 1 ms 3452 KB
021.txt AC 1 ms 3400 KB
022.txt AC 1 ms 3636 KB
023.txt AC 1 ms 3516 KB
024.txt AC 1 ms 3596 KB
025.txt AC 1 ms 3444 KB
026.txt WA 1 ms 3592 KB
027.txt WA 1 ms 3448 KB
028.txt WA 1 ms 3436 KB
029.txt WA 1 ms 3512 KB
030.txt WA 1 ms 3592 KB
031.txt WA 1 ms 3448 KB
032.txt AC 1 ms 3592 KB
033.txt WA 1 ms 3508 KB
034.txt WA 1 ms 3452 KB
035.txt WA 1 ms 3520 KB
036.txt WA 1 ms 3504 KB
037.txt RE 75 ms 3268 KB
example0.txt AC 1 ms 3444 KB
example1.txt AC 1 ms 3516 KB
example2.txt AC 1 ms 3432 KB
example3.txt AC 1 ms 3516 KB


2025-03-05 (Wed)
12:20:21 +00:00