제출 #476745

#제출 시각아이디문제언어결과실행 시간메모리
476745ponytailArranging Shoes (IOI19_shoes)C++17
30 / 100
221 ms140536 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; int n; int inv(int x){ if(x<0) return -x; else if(x>n) return x - n; else return x + n; } ll same_size(vector<int> S) { ll ans1 = 0, ans2 = 0; n = S.size() / 2; queue<int> mp[2 * n + 2]; int nxt = 0; for(int i=0; i<2*n; i++) { if(mp[inv(S[i])].size()){ ans1 += abs(mp[inv(S[i])].front() - nxt) + abs(i - nxt - 1); ans2 += (S[i]<0); nxt += 2; mp[inv(S[i])].pop(); } else{ mp[inv(inv(S[i]))].push(i); } } return ans1 / 2 + ans2; } ll count_swaps(vector<int> S){ map<int, vector<int> > mp; for(int i=0; i<S.size(); i++) { mp[abs(S[i])].push_back(S[i]); } ll ans = 0; for(auto x: mp) { ans += same_size(x.second); } map<int, int> freq; for(int i=0; i<S.size(); i++) { if(freq[abs(S[i])] & 1) S[i] = abs(S[i]); else S[i] = -abs(S[i]); freq[abs(S[i])]++; } ans += same_size(S); return ans; }

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

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