結果

問題 No.2719 Equal Inner Products in Permutation
ユーザー Shreyan RayShreyan Ray
提出日時 2024-04-05 23:11:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,125 bytes
コンパイル時間 2,341 ms
コンパイル使用メモリ 208,944 KB
実行使用メモリ 17,800 KB
最終ジャッジ日時 2024-04-05 23:11:51
合計ジャッジ時間 7,491 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 54 ms
15,516 KB
testcase_16 AC 61 ms
17,060 KB
testcase_17 AC 38 ms
12,012 KB
testcase_18 AC 60 ms
17,292 KB
testcase_19 AC 51 ms
14,948 KB
testcase_20 AC 34 ms
11,260 KB
testcase_21 AC 62 ms
17,356 KB
testcase_22 AC 45 ms
13,968 KB
testcase_23 AC 39 ms
12,660 KB
testcase_24 AC 33 ms
10,964 KB
testcase_25 AC 64 ms
17,800 KB
testcase_26 AC 63 ms
17,800 KB
testcase_27 AC 63 ms
17,800 KB
testcase_28 AC 64 ms
17,800 KB
testcase_29 AC 65 ms
17,800 KB
testcase_30 AC 63 ms
17,800 KB
権限があれば一括ダウンロードができます

ソースコード

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