제출 #423626

#제출 시각아이디문제언어결과실행 시간메모리
423626MazaalaiArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms204 KiB
#include "shoes.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; long long count_swaps(vector<int> s) { ll ans = 0, n = s.size(); map <int, vector <int> > l, r; for (int i = 0; i < n; i++) { if (s[i] < 0) l[-s[i]].push_back(i); else r[s[i]].push_back(i); } vector <pair <int, int> > lines; vector <int> lineCnt(n+5, 0); for (auto el : l) { int val = el.first; vector <int> a = el.second, b = r[val]; for (int i = 0; i < a.size(); i++) { int x = a[i], y = b[i]; if (x < y && x + 1 <= y) { ans += y - (x+1); lines.push_back({x+1, y}); // cout << x+1 << ' ' << y <<": "; lineCnt[x+1]++; // cout << "line1: " << x+1; lineCnt[y+1]--; // cout << ", " << y << '\n'; } if (x > y && y <= x-1) { swap(x, y); ans += y - x; lines.push_back({x, y}); // cout << x << ' ' << y <<": "; lineCnt[x]++; // cout << "line2: " << x; lineCnt[y+1]--; // cout << ", " << y << '\n'; } } } // cout << ans << '\n'; for (int i = 1; i < n+5; i++) lineCnt[i] += lineCnt[i-1]; // for (int i = 0; i < n; i++) cout << lineCnt[i] << ' '; // cout << '\n'; for (auto [a, b] : lines) { // cout << a << ' ' << b << '\n'; if (lineCnt[a] != lineCnt[b]) { // cout << a << ' ' << b << ' ' << lineCnt[a] << ' ' << lineCnt[b] << '\n'; ans -= abs(lineCnt[b] - lineCnt[a]); } } // sort(lines.begin(), lines.end()); // for return ans; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < a.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...