結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
|
提出日時 | 2016-06-14 18:51:19 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,342 bytes |
コンパイル時間 | 476 ms |
コンパイル使用メモリ | 58,972 KB |
実行使用メモリ | 13,632 KB |
最終ジャッジ日時 | 2024-11-06 19:55:36 |
合計ジャッジ時間 | 3,733 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 WA * 3 TLE * 1 -- * 23 |
ソースコード
#include<iostream> #include<algorithm> #define ANS(n) {cout << n << endl; return 0;} using namespace std; typedef long long ll; int* cloneTree(int* tr){ int *clone = new int[3]; for(int i=0; i<3; i++){ clone[i] = tr[i]; } return clone; } bool check(int* tr){ if(tr[0] == tr[1] || tr[1] == tr[2] || tr[2] == tr[0]) return false; if(tr[0] < tr[1] && tr[1] > tr[2]) return true; if(tr[0] > tr[1] && tr[1] < tr[2]) return true; return false; } // UNDONE int main(){ int d; cin >> d; int *h = new int[3]; for(int i=0; i<3; i++){ cin >> h[i]; } // 最初から条件を満たしている if(check(h)) ANS(0) else if(d==0) ANS(-1) // むり // all same if(h[0] == h[1] && h[1] == h[2]){ if(h[0] == 0) ANS(-1) // むり else if(h[0] - d > 0) ANS(3) else ANS(-1) } // 左右どちらかが飛び出していて残り2つは同じ else if( (h[0] == h[1] && h[0] < h[2]) || (h[1] == h[2] && h[0] > h[1]) ){ if(h[1] == 0) ANS(-1) else ANS(1) } // 左右どちらかだけ低い else if( (h[0] == h[1] && h[0] > h[2]) || (h[1] == h[2] && h[0] < h[1]) ){ if(min(h[0], h[2]) == 0){ if(h[1]-d >0) ANS(1) else ANS(-1) } else { if(h[1]-d != min(h[0], h[2])) ANS(1) // 低くない方の左右端を削る else ANS(2) } } // 真ん中だけが飛び出している else if(h[0] == h[2]){ // 真ん中が大きい if(h[0] < h[1]){ if(h[0] == 0) ANS(-1) else ANS(1) } // 真ん中が小さい else{ // 真ん中が0 if(h[1] == 0){ if(h[0]-d <= 0) ANS(-1) else ANS(1) } else{ if(h[0]-d > h[1]) ANS(1) else { // 階段状 if(h[0]-d <= 0) ANS(-1) else ANS(2) } } } } // 階段状 else if((h[0] > h[1] && h[1] > h[2]) || (h[0] < h[1] && h[1] < h[2]) ){ int tmp=-1; int cnt=0; int c_h = h[1]; int* clone = cloneTree(h); while(c_h>0){ // 真ん中削ってみる cnt++; c_h -= d; if(c_h < 0) c_h = 0; clone[1] = c_h; if(check(clone)) { tmp=cnt; break; } } int higher = h[0]>h[2]?0:2; int h_h = h[higher]; cnt = 0; clone = cloneTree(h); while(h_h>0) {// 高い方削ってみる cnt++; h_h -= d; if(h_h < 0) h_h = 0; clone[higher] = h_h; if(check(clone)){ tmp=min(cnt,tmp); break; } } ANS(tmp) } // 多分ここには来ない ANS(-1); }