結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-11-30 05:30:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 2,135 bytes |
| コンパイル時間 | 987 ms |
| コンパイル使用メモリ | 96,276 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-06 20:44:03 |
| 合計ジャッジ時間 | 2,631 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>
#include <valarray>
#include<cassert>//assert();
//#include <random>//xAOJ
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
/////////
vector<LL> H(3);
bool check(){
if( H[0] == H[1] || H[1] == H[2] || H[2] == H[0] ){
return false;
}else if( H[0] < H[1] && H[2] < H[1] ){
return true;
}else if( H[0] > H[1] && H[2] > H[1] ){
return true;
}
return false;
}
LL cut(LL A,LL B,LL C,LL d){
//A>B>C
LL ret = 0;
LL temp;
if( A <= B ){
temp = (B-A+d)/d;
B = B - d*temp;
if( B < 0 ){
B = 0;
}
if( A > B && B > 0){
ret += temp;
}else{
return -1;
}
}
///////////////
if( B <= C ){
temp = (C-B+d)/d;
C = C - d*temp;
if( C < 0 ){
C = 0;
}
if( B > C && C >= 0){
ret += temp;
}else{
return -1;
}
}
return ret;
}
void solve(){
LL d;
cin >> d;//
rep(i,3){
cin >> H[i];
}
if( 0 == d ){
if( check() ){
cout << 0 << endl;
}else{
cout << -1 << endl;
}
return;
}
//else if(H[0] >= 3*d && H[1]>= 3*d && H[2] >= 3*d){}
////
LL ret = -1;
LL temp;
//LL cut(int A,int B,int C,int d)
//(1,0,2)(1,2,0)(0,2,1)(2,0,1)
temp = cut(H[1],H[0],H[2],d);
if( temp >= 0 ){if( -1 == ret || temp < ret){ret = temp;}}
temp = cut(H[1],H[2],H[0],d);
if( temp >= 0 ){if( -1 == ret || temp < ret){ret = temp;}}
temp = cut(H[0],H[2],H[1],d);
if( temp >= 0 ){if( -1 == ret || temp < ret){ret = temp;}}
temp = cut(H[2],H[0],H[1],d);
if( temp >= 0 ){if( -1 == ret || temp < ret){ret = temp;}}
cout << ret << endl;
}
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
//cout << setprecision(16);//
//cpp
solve();
return 0;
}
IL_msta