結果
| 問題 | No.281 門松と魔法(1) |
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-11-06 19:06:37 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 888 bytes |
| 記録 | |
| コンパイル時間 | 154 ms |
| コンパイル使用メモリ | 39,808 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-05-07 02:30:01 |
| 合計ジャッジ時間 | 2,194 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#include <stdio.h>
#define ERR 2000000000
int main(void) {
int d, h1, h2, h3;
scanf("%d%d%d%d", &d, &h1, &h2, &h3);
int a = 0;
if(d == 0) {
if( (h1 < h2 && h3 < h2 && h1 != h3) || (h2 < h1 && h2 < h3 && h1 != h3) ) {}
else { a = -1; }
} else {
if(h1 < h3) {
int temp = h1;
h1 = h3;
h3 = temp;
}
if(h1 == h3) {
h3 = (h3 < d ? 0 : h3 - d);
a++;
}
if(h1 == h3) { a = -1; } else {
if( (h1 < h2 && h3 < h2) || (h2 < h1 && h2 < h3) ) {}
else {
int x = (h1 - h2) / d + 1;
h1 = (h1 < x * d ? 0 : h1 - x * d);
if(h1 == h3) {
h1 = (h1 < d ? 0 : h1 - d);
x++;
if(h1 == h3) { x = ERR; }
}
int y = (h2 - h3) / d + 1;
h2 = (h2 < y * d ? 0 : h2 - y * d);
if(h2 == h3) { y = ERR; }
int z = (x < y ? x : y);
if(z == ERR) { a = -1; } else { a += z; }
}
}
}
printf("%d\n", a);
return 0;
}
FF256grhy