結果
問題 | No.966 引き算をして門松列(その1) |
ユーザー |
![]() |
提出日時 | 2020-01-16 09:32:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 6 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 746 ms |
コンパイル使用メモリ | 94,288 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 09:26:14 |
合計ジャッジ時間 | 1,305 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 |
ソースコード
/* -*- coding: utf-8 -*- * * 966.cc: No.966 引き算をして門松列(その1) - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int INF = 1 << 30; /* typedef */ /* global variables */ /* subroutines */ int check(int p, int q, int r) { int s = 0; int d0 = q - r + 1; if (d0 > 0) q -= d0, s += d0; int d1 = p - q + 1; if (d1 > 0) p -= d1, s += d1; return (p < 1 || q < 1 || r < 1) ? INF : s; } inline void setmin(int &a, int b) { if (a > b) a = b; } /* main */ int main() { int t; scanf("%d", &t); while (t--) { int a, b, c; scanf("%d%d%d", &a, &b, &c); int mind = INF; setmin(mind, check(a, c, b)); setmin(mind, check(c, a, b)); setmin(mind, check(b, a, c)); setmin(mind, check(b, c, a)); printf("%d\n", (mind >= INF) ? -1 : mind); } return 0; }