Submission #63523282


Source Code Expand

#include <bits/stdc++.h>
//#pragma GCC optimize("O3,Ofast,omit-frame-pointer,unroll-all-loops,tree-loop-vectorize,tree-slp-vectorize")
using namespace std;
#define F0(i,n) for (int i=0; i<n; i++)
#define F1(i,n) for (int i=1; i<=n; i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define SZ(x) ((int)x.size())
const int inf = 1000000009;
const double pi = acos(-1.0);
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const double EPS = 1e-9;
const int MOD = 998244353;
//const int MOD = 1000000007;
#define PR(x) cerr << #x << "=" << x << endl
template<class A, class B>
ostream& operator<<(ostream& os, const pair<A, B>& p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<class A, class B, class C>
ostream& operator<<(ostream& os, const tuple<A, B, C>& p) { os << "(" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << ")"; return os; }
istream& operator>>(istream& is, pii& p) { is>>p.first>>p.second; return is; }
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; F0(i,SZ(v)) { if (i>0) os << ","; os << v[i]; } os << "]"; return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T>& v) {
    os << "{"; int f=1; for(auto i:v) { if(f)f=0;else os << ","; cerr << i; } os << "}"; return os;
}
template<class T, class R>
ostream& operator<<(ostream& os, const map<T,R>& v) {
    os << "{"; int f=1; for(auto i:v) { if(f)f=0;else os << ", "; cerr << i.first << ":" << i.second; } os << "}"; return os;
}
//ostream& operator<<(ostream& os, const mint& v) { os << v.val(); return os; }

int n, m, i, j, k, tn;
const int N = 200001;
const int DX[]={-1,0,1,0};
const int DY[]={0,1,0,-1};
const string CS="nesw";
const string HS="URDL";
vector<pii> adj[N];
ll a[N], b[N], c[N];
vector<pii> r;
int v[N];
string s;
ll ans;

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//gp_hash_table<int, int> M;
//#include <atcoder/all>

void Solve2() {
    cin >> n >> m;
    F0(i, n) cin >> a[i];
    F0(i, m) cin >> b[i];
    sort(a, a + n);
    reverse(a, a + n);
    sort(b, b + m);
    reverse(b, b + m);

    for (int i = n - 1; i >= 0; i--) {
        c[i] = max(0LL, c[i + 1] + a[i]);
    }

    ll s = 0;
    F0(i, min(n, m)) {
        s += b[i] + a[i];
        ans = max(ans, s + c[i + 1]);
    }
    cout << ans;
}

bool DFS(int i) {
    r.push_back(pii(i, a[i]));
    v[i] = 1;
    for (pii p : adj[i]) if (!v[p.first]) {
        a[p.first] = a[i] ^ p.second;
        DFS(p.first);
    } else if (a[p.first] != (a[i] ^ p.second)) return false;
    return true;
}

void Solve() {
    cin >> n >> m;
    while (m--) {
        cin >> i >> j >> k;
        adj[i].push_back(pii(j, k));
        adj[j].push_back(pii(i, k));
    }
    F1(i, n) if (!v[i]) {
        r.clear();
        if (!DFS(i)) {
            cout << -1;
            return;
        }
        F0(k, 30) {
            int cnt = 0;
            for (pii p : r) if (p.second & (1<<k)) cnt++; else cnt--;
            if (cnt > 0) {
                for (pii p : r) a[p.first] ^= (1<<k);
            }
        }
    }
    F1(i, n) cout << a[i] << " ";
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    ignore = freopen("x.in", "r", stdin);
    //ignore = freopen("x.out", "w", stdout);
#endif

//#define MULTI_TEST
#ifdef MULTI_TEST
cin >> tn;
string A;
getline(cin, A);

F1(tt, tn) {
    //cout << "Case #" << tt << ": ";
#endif
    Solve();
#ifdef MULTI_TEST
}
#endif
    return 0;
}

Submission Info

Submission Time
Task E - Min of Restricted Sum
User nikaj
Language C++ 17 (Clang 16.0.6)
Score 450
Code Size 3645 Byte
Status AC
Exec Time 92 ms
Memory 19060 KiB

Compile Error

./Main.cpp:8:11: warning: unused variable 'inf' [-Wunused-const-variable]
const int inf = 1000000009;
          ^
./Main.cpp:13:14: warning: unused variable 'EPS' [-Wunused-const-variable]
const double EPS = 1e-9;
             ^
./Main.cpp:14:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 998244353;
          ^
./Main.cpp:38:11: warning: unused variable 'DX' [-Wunused-const-variable]
const int DX[]={-1,0,1,0};
          ^
./Main.cpp:39:11: warning: unused variable 'DY' [-Wunused-const-variable]
const int DY[]={0,1,0,-1};
          ^
5 warnings generated.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 38
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 4 ms 8196 KiB
00_sample_01.txt AC 4 ms 8044 KiB
00_sample_02.txt AC 4 ms 8328 KiB
01_handmade_00.txt AC 4 ms 8120 KiB
01_handmade_01.txt AC 20 ms 8904 KiB
01_handmade_02.txt AC 4 ms 8128 KiB
01_handmade_03.txt AC 4 ms 8152 KiB
01_handmade_04.txt AC 4 ms 8200 KiB
01_handmade_05.txt AC 4 ms 8144 KiB
01_handmade_06.txt AC 20 ms 8976 KiB
01_handmade_07.txt AC 70 ms 16732 KiB
01_handmade_08.txt AC 65 ms 16776 KiB
01_handmade_09.txt AC 21 ms 10484 KiB
02_random_00.txt AC 63 ms 13932 KiB
02_random_01.txt AC 62 ms 13268 KiB
02_random_02.txt AC 84 ms 15032 KiB
02_random_03.txt AC 89 ms 14812 KiB
02_random_04.txt AC 30 ms 11128 KiB
02_random_05.txt AC 63 ms 13352 KiB
02_random_06.txt AC 69 ms 15396 KiB
02_random_07.txt AC 92 ms 14796 KiB
02_random_08.txt AC 43 ms 11852 KiB
02_random_09.txt AC 44 ms 12220 KiB
02_random_10.txt AC 25 ms 11012 KiB
02_random_11.txt AC 45 ms 12420 KiB
02_random_12.txt AC 40 ms 12252 KiB
02_random_13.txt AC 76 ms 14812 KiB
02_random_14.txt AC 40 ms 12508 KiB
02_random_15.txt AC 39 ms 13740 KiB
02_random_16.txt AC 46 ms 13084 KiB
02_random_17.txt AC 74 ms 14772 KiB
02_random_18.txt AC 37 ms 11716 KiB
02_random_19.txt AC 85 ms 14540 KiB
02_random_20.txt AC 13 ms 9920 KiB
02_random_21.txt AC 68 ms 19060 KiB
02_random_22.txt AC 36 ms 11444 KiB
02_random_23.txt AC 61 ms 13728 KiB
02_random_24.txt AC 20 ms 10804 KiB