結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー Shreyan Ray
提出日時 2024-04-05 23:11:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 201,956 KB
最終ジャッジ日時 2025-02-20 22:01:16
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

vector <int> s1, s2, s3;

void work2(vector <int> a){
    int n = a.size();
    int m = n / 3;
    for (int i = 0; i < m; i++){
        s1.push_back(a[i]);
        s2.push_back(a[i + m]);
        s3.push_back(a[i + 2 * m]);
    }
}

void work(int n){
    if (n == 2){
        work2({1, 4, 3, 6, 5, 2});
    } else if (n == 3){
        work2({1, 2, 8, 3, 6, 9, 7, 5, 4});
    } else if (n == 4){
        work2({1, 2, 4, 11, 7, 9, 10, 12, 8, 5, 6, 3});
    } else if (n == 5) {
        work2({1, 2, 3, 8, 13, 7, 10, 12, 14, 15, 11, 9, 6, 4, 5});
    } else {
        work(n - 4);
        int m = 3 * n - 12;
        work2({m + 5, m + 8, m + 10, m + 11, m + 1, m + 2, m + 3, m + 4, m + 6, m + 7, m + 9, m + 12});
    }
}

void Solve() 
{
    int n; cin >> n;
    
    if (n == 1){
        cout << -1 << "\n";
        return;
    }
    
    work(n);
    
    int v1 = 0, v2 = 0;
    vector <bool> ok(3 * n + 1, false);
    for (int i = 0; i < n; i++){
        v1 += s1[i] * s2[i];
        v2 += s2[i] * s3[i];
        ok[s1[i]] = true;
        ok[s2[i]] = true;
        ok[s3[i]] = true;
    }
    
    for (auto x : s1) cout << x << " ";
    for (auto x : s2) cout << x << " ";
    for (auto x : s3) cout << x << " ";
    
    if (v1 != v2){
        cout << "NOOO\n";
    }
    for (int i = 1; i <= 3 * n; i++) if (!ok[i]){
        cout << "NOOB\n";
    }
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // freopen("in",  "r", stdin);
    // freopen("out", "w", stdout);
    
   // cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
0