結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-18 23:42:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,400 bytes |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 83,148 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-06 19:29:24 |
| 合計ジャッジ時間 | 2,158 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 49 WA * 8 |
ソースコード
#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;
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 < b && b > c && a != c) || (a > b && b < c && a != c)) {
return true;
}
return false;
}
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 ((H[0] == 0 && H[1] == 0) || (H[1] == 0 && H[2] == 0) || (H[0] == 0 && H[2] == 0)) {
output(-1, 0);
return 0;
}
if (d == 0 && !isTake(H[0], H[1], H[2])) {
output(-1, 0);
return 0;
}
if (d == 0 && isTake(H[0], H[1], H[2])) {
output(0, 0);
return 0;
}
// case どれかが0
if (H[1] == 0) {
output((H[0] == H[2]) ? 1 : 0, 0);
return 0;
}
if (H[0] == 0) {
if (H[1] > H[2]) {
output(0, 0);
return 0;
}
if ((H[1] <= d && H[2] % d == 0) || H[2] <= d) {
output(-1, 0);
return 0;
}
int ret = (H[2] - H[1]) / d + 1;
output(ret, 0);
return 0;
}
if (H[2] == 0) {
if (H[1] > H[0]) {
output(0, 0);
return 0;
}
if ((H[1] <= d && H[0] % d == 0) || H[0] <= d) {
output(-1, 0);
return 0;
}
int ret = (H[1] > H[0]) ? 0 : (H[0] - H[1]) / d + 1;
output(ret, 0);
return 0;
}
if (isTake(H[0], H[1], H[2])) {
output(0, 0);
return 0;
}
int ret = min((H[1] - H[0]) / d + 1, (H[2] - H[1]) / d + 1);
output(ret, 0);
return 0;
}