結果

問題 No.1571 All Your Cycles Are Same Lengths
ユーザー どららどらら
提出日時 2021-06-27 14:12:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 3,924 ms
コンパイル使用メモリ 227,888 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-07 17:45:12
合計ジャッジ時間 4,943 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,388 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,384 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 4 ms
4,384 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 5 ms
4,384 KB
testcase_08 AC 6 ms
4,384 KB
testcase_09 AC 6 ms
4,384 KB
testcase_10 AC 6 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
//using mint = modint1000000007;
//using mint = modint998244353;


void solve(int N, int T){
  
  if(T%N==0){
    int a = T/N;
    cout << "Yes" << endl;
    rep(i,N){
      REP(j,i+1,N){
        cout << i+1 << " " << j+1 << " " << a << endl;
      }
    }
    return;
  }

  if(N > 2){
    int x = 2;
    int y = N-2;
    int a = -1;
    int b = -1;
    rep(aa,101){
      rep(bb,101){
        if(x*aa + y*bb == T){
          a = aa;
          b = bb;
        }
      }
    }
    if(a >= 0){
      cout << "Yes" << endl;
      rep(i,N){
        REP(j,i+1,N){
          if(i==0) cout << i+1 << " " << j+1 << " " << a << endl;
          else cout << i+1 << " " << j+1 << " " << b << endl;
        }
      }
      return;
    }
  }

  cout << "No" << endl;
}

int main(){
  int Q;
  cin >> Q;
  rep(q,Q){
    int N, T;
    cin >> N >> T;
    solve(N, T);
  }
  return 0;
}

0