結果
問題 |
No.966 引き算をして門松列(その1)
|
ユーザー |
|
提出日時 | 2020-07-04 04:13:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 976 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 191,616 KB |
最終ジャッジ日時 | 2025-01-11 15:20:55 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) const int INF = numeric_limits<int>::max(); int solve() { int a, b, c; int at, bt, ct; cin >> a >> b >> c; int ret = INF; // b is max int x = 0; at = a, bt = b, ct = c; if (at >= bt) { x += at - bt + 1; at = bt - 1; } if (ct >= bt) { x += ct - bt + 1; ct = bt - 1; } if (at == ct) { ++x; --at; } if (at > 0 && bt > 0 && ct > 0) ret = min(ret, x); // b is min int y = 0; at = a, bt = b, ct = c; if (at == ct) { --at; ++y; } if (bt >= at) { y += bt - at + 1; bt = at - 1; } if (bt >= ct) { y += bt - ct + 1; bt = ct - 1; } if (at > 0 && bt > 0 && ct > 0) ret = min(ret, y); if (ret == INF) return -1; return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { cout << solve() << endl; } return 0; }