Submission #421705

#TimeUsernameProblemLanguageResultExecution timeMemory
421705alireza_kavianiSeats (IOI18_seats)C++11
25 / 100
4067 ms110476 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin() , (x).end() const int MAXN = 1e6 + 10; int n , h , w , A[2][MAXN] , first[2][MAXN] , mn[2] , mx[2]; vector<int> vec[2][MAXN]; void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { h = H; w = W; n = h * w; for(int i = 0 ; i < n ; i++){ A[0][i] = R[i]; A[1][i] = C[i]; vec[0][A[0][i]].push_back(i); vec[1][A[1][i]].push_back(i); } for(int i = 0 ; i < h ; i++) first[0][i] = *min_element(all(vec[0][i])); for(int i = 0 ; i < w ; i++) first[1][i] = *min_element(all(vec[1][i])); } void change(int i , int x , int a , int b){ for(int j = 0 ; j < vec[i][x].size() ; j++){ if(vec[i][x][j] == a) vec[i][x][j] = b; } first[i][x] = *min_element(all(vec[i][x])); } int swap_seats(int a, int b) { if(a > b) swap(a , b); int ans = 0; for(int i = 0 ; i < 2 ; i++){ if(A[i][a] == A[i][b]) continue; change(i , A[i][a] , a , b); change(i , A[i][b] , b , a); swap(A[i][a] , A[i][b]); } vector<int> vec; for(int i = 0 ; i < h ; i++) vec.push_back(first[0][i]); for(int i = 0 ; i < w ; i++) vec.push_back(first[1][i]); sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin()); vec.push_back(n); mn[0] = mn[1] = MAXN; mx[0] = mx[1] = -1; for(int i = 0 ; i + 1 < vec.size() ; i++){ int pos = vec[i]; mn[0] = min(mn[0] , A[0][pos]); mx[0] = max(mx[0] , A[0][pos]); mn[1] = min(mn[1] , A[1][pos]); mx[1] = max(mx[1] , A[1][pos]); int x = (mx[0] - mn[0] + 1) , y = (mx[1] - mn[1] + 1); if(vec[i] < x * y && x * y <= vec[i + 1]) ans++; } return ans; }

Compilation message (stderr)

seats.cpp: In function 'void change(int, int, int, int)':
seats.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for(int j = 0 ; j < vec[i][x].size() ; j++){
      |                  ~~^~~~~~~~~~~~~~~~~~
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0 ; i + 1 < vec.size() ; i++){
      |                  ~~~~~~^~~~~~~~~~~~
#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...