제출 #143874

#제출 시각아이디문제언어결과실행 시간메모리
143874stoyan_malininArranging Shoes (IOI19_shoes)C++14
10 / 100
1073 ms1704 KiB
#include<iostream> #include<cstring> #include<vector> #include<queue> using namespace std; const int MAXN = 1005; struct fenwickTree { int tree[MAXN]; fenwickTree() { memset(this->tree, 0, sizeof(this->tree)); } void update(int index, int value) { index++; while(index<MAXN) { this->tree[index] += value; index += index&(-index); } } int query(int index) { int sum = 0; index++; while(index>0) { sum += this->tree[index]; index -= index&(-index); } return sum; } }; fenwickTree *T = new fenwickTree(); queue <int> leftShoes[MAXN], rightShoes[MAXN]; int bestLeft[MAXN], bestRight[MAXN]; int moveElement(int i, int j, vector <int> &s) { int cnt = 0; while(j>i) { cnt++; swap(s[j-1], s[j]); j--; } return cnt; } int calcValue(int num, int index) { int sum = (bestLeft[num] - index) + (bestRight[num] - (index+1)); if(bestLeft[num]>bestRight[num]) sum++; return sum; } long long count_swaps(vector <int> s) { for(int i = 0;i<s.size();i++) { if(s[i]<0) leftShoes[ -s[i] ].push(i); else rightShoes[ s[i] ].push(i); } int answer = 0; for(int index = 0;index<s.size();index+=2) { memset(bestLeft, -1, sizeof(bestLeft)); /* for(int i = s.size()-1;i>=index;i--) { if(s[i]<0) bestLeft[ -s[i] ] = i; else bestRight[ s[i] ] = i; } */ int bestIndex = -1; bestIndex = abs(s[index]); bestLeft[bestIndex] = leftShoes[bestIndex].front() - T->query(leftShoes[bestIndex].front());leftShoes[bestIndex].pop(); bestRight[bestIndex] = rightShoes[bestIndex].front() - T->query(rightShoes[bestIndex].front());rightShoes[bestIndex].pop(); T->update(bestLeft[bestIndex], 1); T->update(bestRight[bestIndex], 1); //cout << " " << bestIndex << '\n'; answer += calcValue(bestIndex, 0); } //for(int i = 0;i<s.size();i++) cout << s[i] << " "; //cout << '\n'; return answer; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:73:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i<s.size();i++)
                   ~^~~~~~~~~
shoes.cpp:80:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int index = 0;index<s.size();index+=2)
                       ~~~~~^~~~~~~~~
#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...