Submission #211065

#TimeUsernameProblemLanguageResultExecution timeMemory
211065_Ice_Tea_Arranging Shoes (IOI19_shoes)C++14
50 / 100
603 ms4856 KiB
#include "shoes.h" #include<bits/stdc++.h> #define LLI long long int #define pii pair<int,int> #define ULTRA 2134567890 #define de(x) if( x && x == MODE) #define MODE 0 using namespace std; int cht[1007][2]; long long count_swaps(std::vector<int> s) { int i,j; pii mini = { ULTRA, 0}; int n = s.size(); LLI ans = 0; for( i=0; i<n; i+=2) { memset( cht, 0x7f, sizeof( cht)); LLI mini = ULTRA; int l; int r; for( j=n-1; j>=i; j--) { if( s[j] < 0) { cht[ -s[j] ][0] = j; } else { cht[ s[j] ][1] = j; } int color = abs(s[j]); if( cht[ color ][0] + cht[ color ][1] < mini) { mini = cht[ color ][0] + cht[ color ][1]; l = cht[ color ][0]; r = cht[ color ][1]; } } for( j=l; j>i; j--) { swap( s[j], s[j-1]); if( j == r) r++; ans++; } for( j=r; j>i+1; j--) { swap( s[j], s[j-1]); ans++; } de(1) { printf("( %d, %d)\n", l, r); for( auto it:s) { printf("%d ", it); } printf("\n"); } } return ans; } // int main() // { // int i,j; // int n; // // scanf("%d", &n); // // vector<int> s; // for( i=0; i<n; i++) // { // int a; // scanf("%d", &a); // s.push_back(a); // } // LLI ans = count_swaps(s); // printf("%lld\n", ans); // return 0; // }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:16:6: warning: variable 'mini' set but not used [-Wunused-but-set-variable]
  pii mini = { ULTRA, 0};
      ^~~~
shoes.cpp:48:6: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
     r++;
     ~^~
shoes.cpp:23:7: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int l;
       ^
#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...