Submission #957346

# Submission time Handle Problem Language Result Execution time Memory
957346 2024-04-03T14:10:45 Z hariaakas646 Coin Collecting (JOI19_ho_t4) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define forr(i, j, k) for (int i = j; i < k; i++)
#define frange(i, j) forr(i, 0, j)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<lli> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long double ld;


void usaco()
{
    freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
//    freopen("problem.out", "w", stdout);
}

int main() {
    // usaco();
    int n;
    scd(n);
    vii v1, v2;

    frange(i, 2*n) {
        int x, y;
        scd(x);
        scd(y);
        if(y >= 2) v2.pb(mp(x, y));
        else v1.pb(mp(x, y));
    }

    sort(all(v1));
    sort(all(v2));

    lli tot = 0;

    for(int i=n; i>=1; i--) {
        pii p1, p2;
        int s1 = v1.size();
        int s2 = v2.size(); 
        if(s1 > s2) {
            
            if(v1[s1-1].f >= i && v1[s1-2].f >= i) {
                p1 = v1.back();
                v1.pop_back();
                p2 = v1.back();
                v1.pop_back();
            }
            else if(v2.size() >= 2 && v2[s2-1].f >= i && v2[s2-2].f >= i) {
                p1 = v2.back();
                v2.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
            else if(v2.size() >= 1 && v2[s2-1].f >= i) {
                p1 = v1.back();
                v1.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
            else {
                p1 = v1.back();
                v1.pop_back();
                p2 = v1.back();
                v1.pop_back();
            }
        }
        else if(s2 > s1) {
            if(v2[s2-1].f >= i && v2[s2-2].f >= i) {
                p1 = v2.back();
                v2.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
            else if(v1.size() >= 2 && v1[s1-1].f >= i && v1[s1-2].f >= i) {
                p1 = v1.back();
                v1.pop_back();
                p2 = v1.back();
                v1.pop_back();
            }
            else if(v1.size() >= 1 && v1[s1-1].f >= i) {
                p1 = v1.back();
                v1.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
            else {
                p1 = v2.back();
                v2.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
        }
        else {
            if(v1[s1-1].f >= i && v2[s2-1].f >= i) {
                p1 = v1.back();
                v1.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
            else if(v1.size() >= 2 && v1[s1-1].f >= i && v1[s1-2].f >= i) {
                p1 = v1.back();
                v1.pop_back();
                p2 = v1.back();
                v1.pop_back();
            }
            else if(v2.size() >= 2 && v2[s2-1].f >= i && v2[s2-2].f >= i) {
                p1 = v2.back();
                v2.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
            else {
                p1 = v1.back();
                v1.pop_back();
                p2 = v2.back();
                v2.pop_back();
            }
        }
        tot += abs(p1.f - i) + abs(p1.s - 1);
        tot += abs(p2.f - i) + abs(p2.s - 2);
    }
    printf("%lld", tot);
}

Compilation message

joi2019_ho_t4.cpp: In function 'void usaco()':
joi2019_ho_t4.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:37:5: note: in expansion of macro 'scd'
   37 |     scd(n);
      |     ^~~
joi2019_ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:42:9: note: in expansion of macro 'scd'
   42 |         scd(x);
      |         ^~~
joi2019_ho_t4.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | #define scd(t) scanf("%d", &t)
      |                ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:43:9: note: in expansion of macro 'scd'
   43 |         scd(y);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -