Submission #19283982


Source Code Expand

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx")
#pragma GCC target ("avx2,fma")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
#define rank fewfewf
#define double long double

using namespace std;
using namespace __gnu_pbds;
using namespace atcoder;


typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1000000;
const int K = 20;
const int mod = 1e9 + 7;
int a[N], b[N], p[N], wh[N], cur[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("input.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    set<pair<int,pair<int,int>>> s;
    for (int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++){
        cin >> p[i];
        s.insert({b[p[i]], {i, p[i]}});
        cur[i] = p[i];
        if (b[p[i]] >= a[i] && p[i] != i){
            cout << -1;
            return 0;
        }
    }
    vector<pair<int,int>> ans;
    while(!s.empty()){
        auto x = *s.rbegin();
        s.erase(prev(s.end()));
        int owner = x.S.F;
        int index = x.S.S;
        int weight = x.F;
        if (a[owner] <= weight && owner != index){
            cout << "-1";
            return 0;
        }
        if (owner == index){
            continue;
        }
        int sw = index;
        ans.pb({sw, owner});
        cur[owner] = cur[sw];
        s.erase({b[cur[sw]], {sw, cur[sw]}});
        s.insert({b[cur[sw]], {owner, cur[sw]}});
    }
    cout << ans.size() << endl;
    for (auto x: ans){
        cout << x.F << " " << x.S << '\n';
    }
}

Submission Info

Submission Time
Task C - Too Heavy
User Wrinx
Language C++ (GCC 9.2.1)
Score 600
Code Size 2079 Byte
Status AC
Exec Time 318 ms
Memory 26308 KiB

Compile Error

./Main.cpp:30:6: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   30 | main(){
      |      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 47
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 1_026.txt, 1_027.txt, 1_028.txt, 1_029.txt, 1_030.txt, 1_031.txt, 1_032.txt, 1_033.txt, 1_034.txt, 1_035.txt, 1_036.txt, 1_037.txt, 1_038.txt, 1_039.txt, 1_040.txt, 1_041.txt, 1_042.txt, 1_043.txt, 1_044.txt, 1_045.txt, 1_046.txt
Case Name Status Exec Time Memory
0_000.txt AC 14 ms 3588 KiB
0_001.txt AC 2 ms 3532 KiB
0_002.txt AC 3 ms 3640 KiB
1_003.txt AC 3 ms 3724 KiB
1_004.txt AC 3 ms 3644 KiB
1_005.txt AC 2 ms 3732 KiB
1_006.txt AC 2 ms 3688 KiB
1_007.txt AC 3 ms 3600 KiB
1_008.txt AC 2 ms 3588 KiB
1_009.txt AC 4 ms 3580 KiB
1_010.txt AC 2 ms 3672 KiB
1_011.txt AC 45 ms 6668 KiB
1_012.txt AC 46 ms 6768 KiB
1_013.txt AC 43 ms 6824 KiB
1_014.txt AC 2 ms 3660 KiB
1_015.txt AC 3 ms 3696 KiB
1_016.txt AC 3 ms 3736 KiB
1_017.txt AC 2 ms 3584 KiB
1_018.txt AC 2 ms 3640 KiB
1_019.txt AC 1 ms 3648 KiB
1_020.txt AC 4 ms 3588 KiB
1_021.txt AC 2 ms 3696 KiB
1_022.txt AC 2 ms 3688 KiB
1_023.txt AC 1 ms 3588 KiB
1_024.txt AC 2 ms 3600 KiB
1_025.txt AC 2 ms 3640 KiB
1_026.txt AC 2 ms 3716 KiB
1_027.txt AC 2 ms 3688 KiB
1_028.txt AC 2 ms 3696 KiB
1_029.txt AC 301 ms 26204 KiB
1_030.txt AC 310 ms 26160 KiB
1_031.txt AC 306 ms 26296 KiB
1_032.txt AC 309 ms 26308 KiB
1_033.txt AC 309 ms 26224 KiB
1_034.txt AC 307 ms 26168 KiB
1_035.txt AC 311 ms 26272 KiB
1_036.txt AC 303 ms 26196 KiB
1_037.txt AC 310 ms 26152 KiB
1_038.txt AC 306 ms 26272 KiB
1_039.txt AC 141 ms 22348 KiB
1_040.txt AC 304 ms 26148 KiB
1_041.txt AC 306 ms 26260 KiB
1_042.txt AC 236 ms 24128 KiB
1_043.txt AC 143 ms 22452 KiB
1_044.txt AC 318 ms 26216 KiB
1_045.txt AC 302 ms 26304 KiB
1_046.txt AC 238 ms 24212 KiB