結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー otoshigo
提出日時 2024-04-06 02:57:52
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,617 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 200,364 KB
最終ジャッジ日時 2025-02-20 22:21:47
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin>>N;
    if(N==1){
        cout<<-1<<"\n";
    }else if(N==2){
        cout<<"1 4 3 6 5 2\n";
    }else if(N==5){
        cout<<"1 2 3 9 15 10 12 13 14 11 4 5 6 7 8\n";
    }else{
        vector<vector<int>>v3={{1,2,9},{6,8,7},{3,4,5}};
        vector<vector<int>>v4={{1,2,5,12},{8,10,11,9},{3,6,4,7}};
        vector<vector<int>>ans(3);
        int s=0;
        for(int i=0;i<4;i++){
            if((N-3*i)%4==0){
                for(int j=0;j<i;j++){
                    for(int k=0;k<3;k++){
                        for(auto x:v3[k]){
                            ans[k].push_back(x+s);
                        }
                    }
                    s+=9;
                }
                for(int j=0;j<(N-3*i)/4;j++){
                    for(int k=0;k<3;k++){
                        for(auto x:v4[k]){
                            ans[k].push_back(x+s);
                        }
                    }
                    s+=12;
                }
            }
        }
        for(int i=0;i<3;i++){
            for(int j=0;j<N;j++){
                cout<<ans[i][j]<<" ";
            }
        }
        cout<<"\n";
    }
}
0