結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-19 20:02:38 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,068 bytes |
| コンパイル時間 | 865 ms |
| コンパイル使用メモリ | 84,404 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 19:36:52 |
| 合計ジャッジ時間 | 2,259 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 WA * 9 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int max_int = 2147483647;
using namespace std;
int inputValue(){
int a;
cin >> a;
return a;
};
void inputArray(int * p, int a){
rep(i, a){
cin >> p[i];
}
};
void inputVector(vector<int> * p, int a){
rep(i, a){
int input;
cin >> input;
p -> push_back(input);
}
}
template <typename T>
void output(T a, int precision) {
if(precision > 0){
cout << setprecision(precision) << a << "\n";
}
else{
cout << a << "\n";
}
}
bool isTake(int a, int b, int c){
if (a < 0 || b < 0 || c < 0){
return false;
}
if ((a < b && b > c && a != c) || (a > b && b < c && a != c)) {
return true;
}
return false;
}
bool isTakev(vector<int> V){
return isTake(V[0], V[1], V[2]);
}
int main(int argc, const char * argv[]) {
// source code
int d = inputValue();
vector<int> H(3);
rep(i, 3){
H[i] = inputValue();
}
// case -1
if (isTake(H[0], H[1], H[2])) {
output(0, 0);
return 0;
}
if (!isTake(H[0], H[1], H[2]) && d == 0) {
output(-1, 0);
return 0;
}
// 真ん中を最小にする場合と最大にする場合両方調べる
int seedC = 0;
int seedE = 0;
if (H[0] == H[2]) {
H[0] = max(0, H[0] - d);
if(H[0] != 0) {
// 両端が0で同じだとどうしようもないので排除
seedC += 1;
seedE += 1;
}
}
vector<int> newHC = H;
// 真ん中を最小にしたい場合 (真ん中に魔法をかける)
if (H[0] <= H[1] && H[0] <= H[2]) {
newHC[1] = H[1] - ((H[1] - H[0]) / d + 1) * d;
seedC += (H[1] - H[0]) / d + 1;
}
if (H[0] <= H[1] && H[0] >= H[2]) {
newHC[1] = H[1] - ((H[1] - H[2]) / d + 1) * d;
seedC += (H[1] - H[2]) / d + 1;
}
vector<int> newHE = H;
// 真ん中を最大にしたい場合 (両端に魔法をかける)
if (H[0] >= H[1]){
newHE[0] = H[0] - ((H[0] - H[1]) / d + 1) * d;
seedE += (H[0] - H[1]) / d + 1;
}
if (H[2] >= H[1]){
newHE[2] = H[2] - ((H[2] - H[1]) / d + 1) * d;
seedE += (H[2] - H[1]) / d + 1;
}
if (newHE[0] == newHE[2]){
newHE[0] = max(0, newHE[0] - d);
if(newHE[0] != 0) {
// 両端が0で同じだとどうしようもないので排除
seedE += 1;
}
}
if (!isTakev(newHC)) {
seedC = max_int;
}
if (!isTakev(newHE)) {
seedE = max_int;
}
if (seedC == max_int && seedE == max_int) {
output(-1, 0);
return 0;
}
else{
output(min(seedC, seedE), 0);
}
return 0;
}