제출 #293935

#제출 시각아이디문제언어결과실행 시간메모리
293935humbertoyustaArranging Shoes (IOI19_shoes)C++14
10 / 100
38 ms8060 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; //#define int long long #define maxn 100010 #define f first #define s second #define db(x) cerr << #x << ": " << (x) << '\n'; int abi[maxn], n; long long ans, lans; pair<pair<int,int>,int> a[maxn]; void update(int id){ for( ; id > 0; id -= ( id & -id ) ) abi[id] ++; } int query(int id){ int res = 0; for( ; id <= n; id += ( id & -id ) ) res += abi[id]; return res; } long long count_swaps(std::vector<int> s) { n = (int)s.size(); for(int i=0; i<n; i++){ a[i+1].f.f = abs( s[i] ); a[i+1].f.s = i + 1; a[i+1].s = s[i]; } for(int i=1; i<=n; i++){//db(a[i].f.f) ans += query(a[i].f.f+1); update(a[i].f.f); } sort(a+1,a+n+1); int c1, c2, l; for(int i=1; i<=n; i++){ if( a[i].f.f != a[i-1].f.f ){ c1 = 0, c2 = 0, l = i; } if( a[i].s < 0 ){ int pos = l + c1 * 2; lans += abs( i - pos ); c1++; } if( a[i].s > 0 ){ int pos = l + 1 + c2 * 2; lans += abs( i - pos ); c2++; } } return ans + ( lans ) / 2; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:44:17: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |             int pos = l + c1 * 2;
      |                 ^~~
shoes.cpp:51:15: warning: 'c2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |             c2++;
      |             ~~^~
shoes.cpp:46:15: warning: 'c1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |             c1++;
      |             ~~^~
#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...