Created
August 10, 2015 13:12
-
-
Save velengel/ebd9920ce01b9d87ef98 to your computer and use it in GitHub Desktop.
PCK2014予選問5 Wrong Answer tc(3/24)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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