Submission #851248

#TimeUsernameProblemLanguageResultExecution timeMemory
85124812345678정렬하기 (IOI15_sorting)C++17
20 / 100
1004 ms15048 KiB
#include "sorting.h" #include <bits/stdc++.h> using namespace std; const int nx=2e3+5; int dp[nx][nx], cnt(0); vector<pair<int, int>> ans; int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) { for (int i=0; i<N; i++) dp[0][i]=S[i]; bool f=1; for (int i=0; i<N; i++) if (S[i]!=i) f=0; if (f) return 0; for (int i=1; i<=N; i++) { for (int j=0; j<N; j++) dp[i][j]=dp[i-1][j]; swap(dp[i][X[i-1]], dp[i][Y[i-1]]); ans.clear(); vector<int> l(N); for (int j=0; j<N; j++) l[j]=dp[i][j]; for (int j=0; j<N; j++) for (int k=j+1; k<N; k++) if (l[k]==j) ans.push_back({j, k}), swap(l[k], l[j]); if (ans.size()<=i) { while (ans.size()<i) ans.push_back({0, 0}); break; } } cnt=ans.size(); for (int i=0; i<cnt; i++) P[i]=ans[i].first, Q[i]=ans[i].second; return cnt; }

Compilation message (stderr)

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:23:23: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |         if (ans.size()<=i)
      |             ~~~~~~~~~~^~~
sorting.cpp:25:30: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |             while (ans.size()<i) ans.push_back({0, 0});
      |                    ~~~~~~~~~~^~
sorting.cpp:29:14: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   29 |  cnt=ans.size();
      |      ~~~~~~~~^~
sorting.cpp:10:39: warning: unused parameter 'M' [-Wunused-parameter]
   10 | int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
      |                                   ~~~~^
#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...