Submission #1039938

#TimeUsernameProblemLanguageResultExecution timeMemory
1039938ZicrusSorting (IOI15_sorting)C++17
54 / 100
94 ms756 KiB
#include <bits/stdc++.h> #include "sorting.h" using namespace std; typedef long long ll; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { ll res = 0; vector<ll> s(N); for (int i = 0; i < N; i++) s[i] = S[i]; for (int i = 0; i < M; i++) { swap(s[X[i]], s[Y[i]]); vector<ll> order = s; for (int j = i+1; j < M; j++) { swap(order[X[j]], order[Y[j]]); } int firstOut = -1, id = -1; for (int j = 0; j < N; j++) { if (order[j] != j) { firstOut = order[id = j]; break; } } if (firstOut == -1) { P[res] = Q[res] = 0; res++; } else { ll v = *find(order.begin(), order.end(), id); ll id1 = find(s.begin(), s.end(), firstOut) - s.begin(); ll id2 = find(s.begin(), s.end(), v) - s.begin(); swap(s[id1], s[id2]); P[res] = id1; Q[res] = id2; res++; } firstOut = -1; for (int j = 0; j < N; j++) { if (s[j] != j) { firstOut = s[j]; break; } } if (firstOut == -1) return res; } P[res] = Q[res] = 0; res++; return res; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:20:40: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   20 |                 firstOut = order[id = j];
      |                                        ^
sorting.cpp:34:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   34 |             P[res] = id1;
      |                      ^~~
sorting.cpp:35:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   35 |             Q[res] = id2;
      |                      ^~~
sorting.cpp:42:31: warning: conversion from '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} to 'int' may change value [-Wconversion]
   42 |                 firstOut = s[j];
      |                               ^
sorting.cpp:46:36: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   46 |         if (firstOut == -1) return res;
      |                                    ^~~
sorting.cpp:51:9: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   51 |  return res;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...