結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-09-18 22:56:18 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,809 bytes |
| コンパイル時間 | 928 ms |
| コンパイル使用メモリ | 77,040 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-06 18:51:58 |
| 合計ジャッジ時間 | 2,398 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 53 WA * 4 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
bool check(vector<long long>& h){
if(h[0] == h[1] || h[1] == h[2] || h[2] == h[0]) return false;
if(h[1] > h[0] && h[1] > h[2]) return true;
if(h[1] < h[0] && h[1] < h[2]) return true;
return false;
}
int main(){
long long d;
cin >> d;
vector<long long> h(3);
for(int i=0; i<3; i++){
cin >> h[i];
}
if(check(h)){
cout << 0 << endl;
return 0;
}
long long ans = -1;
{ // h[1] > h[0],h[2]
vector<long long> h_ = h;
long long tmp = 0;
long long lb = -1;
long long ub = 1e10;
while(ub-lb>1){
long long mid = (ub+lb)/2;
long long len = max(0LL, h_[0] - d*mid);
if(len >= h_[1]){
lb = mid;
}else{
ub = mid;
}
}
h_[0] = max(0LL, h_[0] - d*ub);
tmp += ub;
lb = -1;
ub = 1e10;
while(ub-lb>1){
long long mid = (ub+lb)/2;
long long len = max(0LL, h_[2] - d*mid);
if(len >= h_[1]){
lb = mid;
}else{
ub = mid;
}
}
h_[2] = max(0LL, h_[2] - d*ub);
tmp += ub;
if(h_[0] == h_[2]){
h_[0] = max(0LL, h_[0] - d*ub);
tmp++;
}
if(check(h_)){
ans = tmp;
}
}
{ // h[1] < h[0],h[2]
vector<long long> h_ = h;
long long tmp = 0;
long long lb = -1;
long long ub = 1e10;
while(ub-lb>1){
long long mid = (ub+lb)/2;
long long len = max(0LL, h_[1] - d*mid);
if(len >= h_[0] || len >= h_[2]){
lb = mid;
}else{
ub = mid;
}
}
h_[1] = max(0LL, h_[1] - d*ub);
tmp += ub;
if(h_[0] == h_[2]){
h_[0] = max(0LL, h_[0] - d*ub);
tmp++;
}
if(check(h_)){
if(ans == -1){
ans = tmp;
}else{
ans = min(ans, tmp);
}
}
}
cout << ans << endl;
return 0;
}
koyumeishi