Submission #19284443


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

//#define int long long
//#define ll long long
#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e16;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    map<int, int> cnt;
    for(int i =0 ;i<n;++i) {
        cin >> a[i].first >> a[i].second;
        ++cnt[a[i].first];++cnt[a[i].second];
    }

    set<int> used;
    sort(all(a));
    for (int i = 0;i<n;) {
        int j = i;
        while (j < n - 1 && a[j + 1].first == a[j].first) ++j;
        int id = i, mn = INF;
        for (int c = i;c <= j;++c) {
            if (used.count(a[c].second) || a[c].first == a[c].second) {
                id = c;
                break;
            }else if(mn > cnt[a[c].second]) {
                mn = cnt[a[c].second];
                id = c;
            }
        }
        for (int c = i;c <= j;++c) {
            if (used.count(a[id].first) || c != id) {
                used.insert(a[c].second);
            }
        }
        used.insert(a[id].first);
        i = j + 1;
    }
    cout << used.size();
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(15);
    srand(time(0));
    //freopen("movetofront.in", "r", stdin);
    //freopen("movetofront.out", "w", stdout);
    int t = 1;
    //cin >> t;
    while (t--) solve();
}

Submission Info

Submission Time
Task B - Reversible Cards
User yorky
Language C++ (GCC 9.2.1)
Score 0
Code Size 1558 Byte
Status WA
Exec Time 436 ms
Memory 32976 KB

Compile Error

./Main.cpp:11:17: warning: overflow in conversion from ‘double’ to ‘int’ changes value from ‘2.0e+16’ to ‘2147483647’ [-Woverflow]
   11 | const int INF = 2e16;
      |                 ^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 17
WA × 10
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
Case Name Status Exec Time Memory
0_000.txt AC 5 ms 3560 KB
0_001.txt AC 1 ms 3564 KB
0_002.txt AC 3 ms 3560 KB
1_003.txt WA 1 ms 3608 KB
1_004.txt WA 2 ms 3564 KB
1_005.txt AC 55 ms 4688 KB
1_006.txt WA 4 ms 3600 KB
1_007.txt AC 5 ms 3664 KB
1_008.txt AC 91 ms 4632 KB
1_009.txt WA 372 ms 25572 KB
1_010.txt WA 430 ms 25584 KB
1_011.txt WA 436 ms 25568 KB
1_012.txt AC 268 ms 32976 KB
1_013.txt AC 185 ms 23512 KB
1_014.txt AC 43 ms 4772 KB
1_015.txt AC 152 ms 23488 KB
1_016.txt AC 2 ms 3556 KB
1_017.txt AC 37 ms 6304 KB
1_018.txt AC 84 ms 9968 KB
1_019.txt AC 305 ms 23392 KB
1_020.txt AC 293 ms 23312 KB
1_021.txt AC 3 ms 3448 KB
1_022.txt AC 2 ms 3516 KB
1_023.txt WA 242 ms 18096 KB
1_024.txt WA 120 ms 11868 KB
1_025.txt WA 315 ms 22368 KB
1_026.txt WA 160 ms 14188 KB