Submission #387207

#TimeUsernameProblemLanguageResultExecution timeMemory
387207ismoilovArranging Shoes (IOI19_shoes)C++14
0 / 100
1 ms364 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(x) (x).begin(), (x).end() #define rall(x) (x).begin(), (x).end() #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++) #define fpp(a,i,c) for(int (a) = (i); (a) <= (c); (a)++) #define fv(c) for(int (a) = (1); (a) <= (c); (a)++) #define fz(c) for(int (a) = (0); (a) < (c); (a)++) #define fm(a,i,c) for(int (a) = (i); (a) > (c); (a)--) #define fmm(a,i,c) for(int (a) = (i); (a) >= (c); (a)--) #define pb push_back #define in insert #define ss second #define ff first long long count_swaps(vector<int> s) { ll ans = 0, c = 0; int n = s.size(); vector <int> v[2*n+1]; vector <int> a; vector <int> vis(n+1, 0), mx(n+1, 0); fp(i,0,n){ //cout << mx[abs(s[i])] << " "; if(s[i] < 0){ v[abs(s[i])+n].pb(i+abs(c) - abs(vis[abs(s[i])])); vis[abs(s[i])]--; c += mx[abs(s[i])] - abs(vis[abs(s[i])]); mx[abs(s[i])] = abs(vis[abs(s[i])]); } else{ v[s[i]].pb(i+abs(c)), a.pb(s[i]); vis[s[i]]++; c += mx[s[i]] - abs(vis[s[i]]); mx[abs(s[i])] = abs(vis[abs(s[i])]); } //cout << vis[abs(s[i])] << " " << s[i] << " " << c << "\n"; } for(auto it : a){ while(!v[it].empty()){ int x = v[it].back(), y = v[it+n].back(); v[it].pop_back(), v[it+n].pop_back(); if(x > y) ans += x - y - 1; else ans += y - x; //cout << it << " " << x << " " << y << "\n"; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:10:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fp(a,i,c) for(int (a) = (i); (a) < (c); (a)++)
      |                           ^
shoes.cpp:27:2: note: in expansion of macro 'fp'
   27 |  fp(i,0,n){
      |  ^~
#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...