Skip to content

Instantly share code, notes, and snippets.

@velengel
Created August 10, 2015 13:12
Show Gist options
  • Save velengel/ebd9920ce01b9d87ef98 to your computer and use it in GitHub Desktop.
Save velengel/ebd9920ce01b9d87ef98 to your computer and use it in GitHub Desktop.
PCK2014予選問5 Wrong Answer tc(3/24)
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
int main(){
int N,M,p;
std::cin >> N >> M >> p;
std::vector<int> d;
for(int i = 0; i < M; ++i){
int a;
std::cin>>a;
a -= p;
if(a < 0)a += N;
d.push_back(a);
}
d.push_back(0);
M = d.size();
std::sort(d.begin(), d.end());
int ans = 1e9;
for(int i = 0; i < M; ++i){
//i+1 と i+2番目の間を通らない。0から始める,全通り試す
int bet = abs(d[0] - d[(i + 1) % N]);
int bet2 = N - abs((d[0] - d[(i + 2) % N]));
if(bet > bet2)std::swap(bet, bet2);
ans = std::min(ans, bet * 2 + bet2);
}
std::cout << ans * 100 << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment