結果

問題 No.3506 All Distance is Square Number
コンテスト
ユーザー tau1235
提出日時 2026-04-18 15:22:35
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 761 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,950 ms
コンパイル使用メモリ 340,164 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-18 15:22:44
合計ジャッジ時間 4,290 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  vector<tuple<int,int,int>> edge;
  for (int i=0;i<n-1;i++) edge.push_back({i+1,i+2,i*2+1});
  for (int i=0;i<n-2;i++) edge.push_back({2,i+3,i*2+4});
  int m=edge.size();
  assert(m==2*n-3);
  cout<<m<<endl;
  for (auto [u,v,c]:edge) cout<<u<<" "<<v<<" "<<c<<endl;
  auto f=[&](int s,int t){
    vector<int> ans;
    if (s==0) for (int i=0;i<t;i++) ans.push_back(i);
    else{
      for (int i=s-1;i>=1;i--) ans.push_back(i);
      ans.push_back(n-2+s);
      for (int i=s+1;i<t;i++) ans.push_back(i);
    }
    int k=ans.size();
    cout<<k<<" ";
    int sum=0;
    for (int i=0;i<k;i++) cout<<ans[i]+1<<" \n"[i==k-1];
  };
  for (int i=0;i<n;i++) for (int j=i+1;j<n;j++) f(i,j);
}
0