結果

問題 No.1837 Same but Different
ユーザー RubikunRubikun
提出日時 2022-02-11 22:03:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,052 bytes
コンパイル時間 2,385 ms
コンパイル使用メモリ 206,384 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-10 02:30:23
合計ジャッジ時間 4,378 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,388 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=400005,INF=1<<30;

bool check(vector<int> A,vector<int> B){
    int N=si(A);
    for(int i=0;i<N;i++){
        if(A[i]<0) return false;
        if(A[i]>10000) return false;
        if(B[i]<0) return false;
        if(B[i]>10000) return false;
        if(i+1<N){
            if(A[i]==A[i+1]) return false;
            if(B[i]==B[i+1]) return false;
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                for(int l=0;l<N;l++){
                    if(A[i]+A[j]==B[k]+B[l]) return false;
                }
            }
        }
    }
    
    return true;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    
    int N;cin>>N;
    if(N%3==0){
        for(int i=0;i<N;i++){
            if(i>=N/3*2) cout<<1+3*i+3<<" ";
            else cout<<1+3*i<<" ";
        }
        cout<<endl;
        for(int i=0;i<N;i++){
            cout<<2+3*i<<" ";
        }
        cout<<endl;
    }else if(N%3==1){
        for(int i=0;i<N;i++){
            if(i>=N/3*2+1){
                if(i==N-1) cout<<1+3*i+4<<" ";
                else cout<<1+3*i+3<<" ";
            }
            else cout<<1+3*i<<" ";
        }
        cout<<endl;
        for(int i=0;i<N;i++){
            cout<<2+3*i<<" ";
        }
        cout<<endl;
    }else{
        if(N<=11){
            vector<int> A(N),B(N);
            while(1){
                int sum=0;
                for(int i=0;i<N;i++){
                    A[i]=rng()%10001;
                    sum+=A[i];
                }
                for(int i=0;i<N-1;i++){
                    B[i]=rng()%10001;
                    sum-=B[i];
                }
                B[N-1]=sum;
                sort(all(A));
                sort(all(B));
                if(check(A,B)){
                    for(int i=0;i<N;i++) cout<<A[i]<<" ";
                    cout<<endl;
                    for(int i=0;i<N;i++) cout<<B[i]<<" ";
                    cout<<endl;
                    
                    return 0;
                }
            }
        }
        vector<int> A(N),B(N);
        for(int i=0;i<N;i++){
            A[i]=1+3*i;
            B[i]=2+3*i;
        }
        A[N-2]++;A[N-1]++;
        int ne=(N-2)/3;
        A[N-2]+=min(ne/2,333)*3;
        A[N-1]+=min(ne/2,333)*3;
        ne-=min(ne/2,333)*2;
        A[N-3]+=ne*3;
        
        for(int i=0;i<N;i++) cout<<A[i]<<" ";
        cout<<endl;
        for(int i=0;i<N;i++) cout<<B[i]<<" ";
        cout<<endl;
    }
    
}
0