結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-12 11:31:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 3,746 bytes |
| コンパイル時間 | 1,071 ms |
| コンパイル使用メモリ | 120,384 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 20:42:46 |
| 合計ジャッジ時間 | 2,484 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>
using namespace std;
#define int long long
#define let const auto
#define var auto
#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef complex<double> point;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for(auto it = v.begin(); it != v.end(); ++it){
if(it != v.begin()){
os << ",";
}
os << *it;
}
return os << "}";
}
template<typename T>
void isort(std::vector<T>& v, std::function<bool(T,T)> comp=less<T>()){
sort(v.begin(), v.end(), comp);
}
template<typename T>
std::vector<T> sort(std::vector<T> v, std::function<bool(T,T)> comp=less<T>()){
isort(v);
return v;
}
template<typename T1, typename T2>
std::vector<T2> rmap(const std::vector<T1>& v, std::function<T2(T1)> f){
std::vector<T2> t; t.reserve(v.size());
for(const auto& i: v) t.push_back(f(i));
return t;
}
std::vector<std::string> split(std::string str, char delim){
std::vector<std::string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != std::string::npos){
res.push_back(std::string(str, current, found - current));
current = found + 1;
}
res.push_back(std::string(str, current, str.size() - current));
return res;
}
string join(const std::vector<string>& v, string delim){
string ret = "";
for(auto it = v.begin(); it != v.end(); ++it){
if(it != v.begin()){
ret += delim;
}
ret += *it;
}
return ret;
}
bool check(vector<int> h){
return (h[0] >= 0 && h[1] >= 0 && h[2] >= 0 &&
(h[0] != h[1] && h[1] != h[2] && h[0] != h[2])
&& ((h[0] < h[1] && h[1] > h[2]) ||
(h[0] > h[1] && h[1] < h[2])));
}
int min_solve(int d, vector<int> h){
int ret = 0;
if(h[0] == h[2]){
ret++; h[0] -= d;
}
int diff = h[1] - min(h[0], h[2]);
if(diff < 0) return ret;
int needs = (diff / d) + 1;
h[1] -= d * needs;
h[1] = max(0ll, h[1]);
if(check(h))
return ret + needs;
else
return -1;
}
int max_solve(int d, vector<int> h){
int ret = 0;
vector<int> k = {0,2};
for(int i : k){
int diff = h[i] - h[1];
if(diff >= 0){
int needs = (diff / d) + 1;
ret += needs;
h[i] -= d * needs;
}
}
if(h[0] == h[2]){
ret++;
h[0] -= d;
}
for(int i=0;i<3;i++){
h[i] = max(0ll,h[i]);
}
if(check(h))
return ret;
else
return -1;
}
int solve(int d, vector<int> h){
if(check(h)) return 0;
if(d == 0) return -1;
int mis = min_solve(d,h);
int mas = max_solve(d,h);
if(mis == -1 && mas == -1) return -1;
if(mis == -1) return mas;
if(mas == -1) return mis;
return min(mis,mas);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int d; cin >> d;
vector<int> h(3);
for(int& i: h) cin >> i;
cout << solve(d, h) << endl;
return 0;
}