Submission #971017

# Submission time Handle Problem Language Result Execution time Memory
971017 2024-04-27T19:53:03 Z bigo Sorting (IOI15_sorting) C++14
0 / 100
1 ms 604 KB
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
#define all(a) a.begin(),a.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 1;

vector<vector<int>>mag;
vector<int>we,vec,vec1;
vector<bool>visit;

int ans = 0;

void dfs(int v,int p) {
	visit[v] = true;
	we[v] = p;
	mag[p].push_back(v);
	dfs(vec[v],p);
}

int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[]) {
	mag.resize(n);
	we.resize(n);
	visit.resize(n);
	vec1.resize(n);
	rep(i, 0, n) vec[i] = S[i];
	rep(i, 0, n) {
		vec1[vec[i]] = i;
	}
	int cnt = 0;
	rep(i, 0, n) {
		if (!visit[i]) {
			dfs(i, cnt);
			cnt++;
		}
	}
	ans = 0;
	rep(i, 0, n)
		ans += mag[i].size() - 1;
	if (ans == 0)
		return 0;
	rep(R, 1, m+1) {
		swap(vec[X[R - 1]], vec[Y[R - 1]]);
		swap(vec1[vec[X[R - 1]]], vec1[vec[Y[R - 1]]]);
		mag.clear();
		we.clear();
		visit.clear();
		mag.resize(n);
		we.resize(n);
		visit.resize(n);
		int cnt = 0;
		rep(i, 0, n) {
			if (!visit[i]) {
				dfs(i, cnt);
				cnt++;
			}
		}
		ans = 0;
		rep(i, 0, n)
			ans += mag[i].size() - 1;
		if (ans <= R) {
			int sz = 0;
			rep(i, 0, n) {
				rep(j, 0, mag[i].size() - 1) {
					P[sz] = vec1[mag[i][j]];
					P[sz] = vec1[mag[i][j+1]];
					sz++;
				}
			}
			return R;
		}
	}
}

Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:47:26: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   47 |   ans += mag[i].size() - 1;
      |                          ^
sorting.cpp:59:7: warning: declaration of 'cnt' shadows a previous local [-Wshadow]
   59 |   int cnt = 0;
      |       ^~~
sorting.cpp:38:6: note: shadowed declaration is here
   38 |  int cnt = 0;
      |      ^~~
sorting.cpp:68:27: warning: conversion from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   68 |    ans += mag[i].size() - 1;
      |                           ^
sorting.cpp:12:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
   72 |     rep(j, 0, mag[i].size() - 1) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~  
sorting.cpp:72:5: note: in expansion of macro 'rep'
   72 |     rep(j, 0, mag[i].size() - 1) {
      |     ^~~
sorting.cpp:29:73: warning: unused parameter 'Q' [-Wunused-parameter]
   29 | int findSwapPairs(int n, int S[], int m, int X[], int Y[], int P[], int Q[]) {
      |                                                                     ~~~~^~~
sorting.cpp:81:1: warning: control reaches end of non-void function [-Wreturn-type]
   81 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -