제출 #1004689

#제출 시각아이디문제언어결과실행 시간메모리
1004689zh_hArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define lint long long int #define pb push_back using namespace std; lint count_swaps(vector<int> s){ vector<pair<int, int>> v; for(int i = 0; i < s.size(); i ++){ if(s[i] < 0){v.pb({s[i], -i});} else{v.pb({s[i], i});} // if(s[i] > s[i-1]){ // if(s[i]+s[i-1] == 0){ // v.erase(v.begin()+i-1); // v.erase(v.begin()+i); // } // } } lint ans = 0; sort(v.begin(), v.end()); // for(auto i : v){cout << i.first << " " << i.second << endl;} //* 0 1 2 3 4 5 6 7 8 9 for(int i = 0; i < s.size()/2; i ++){ // cout << ans; int temp = v[(s.size()/2)+i].second + v[(s.size()/2)-1-i].second; if(temp > 0){ ans += temp-1; } else ans+=(0-temp); } // cout << endl << ans << endl; return ans; } // int main(){ // lint temp; // // temp = count_swaps({2, 1, -1, -2}); // // temp = count_swaps({1, -1, 6, 4, -3, 2, 5, -6, -5, -4, -2, 3, -1, 2, -2, 1}); // temp = count_swaps({-2, 2, 2, -2, -2, 2}); // cout << temp; // } // 6, ., ., ., -6 // 2, ., ., ., 7 // -6, -7 // 6, 2 // so first (7-2)-1 // then +1 to switch place // -3, ., ., ., ., 3 // 4, ., ., ., ., 11 // -3 -4 // 3 11 // (11-4)-1 // so if sum > 0, juz -1 // else if sum < 0, juz add negative sign

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:8:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0; i < s.size(); i ++){
      |                    ~~^~~~~~~~~~
shoes.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i < s.size()/2; 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...