Submission #1202166

#TimeUsernameProblemLanguageResultExecution timeMemory
1202166nguynCoin Collecting (JOI19_ho_t4)C++20
100 / 100
26 ms3144 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define F first
#define S second
#define pb push_back 
#define pii pair<int,int>

const int N = 2e5 + 5;

int cnt[N][3];
int x[N], y[N], n; 

signed main(){
    ios_base::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    if (fopen("INP.INP" ,"r")) {
        freopen("INP.INP" ,"r" , stdin) ;
        freopen("OUT.OUT" , "w" , stdout) ;
    }
    cin >> n;
    ll res = 0;
    for (int i = 1; i <= 2 * n; i++) {
    	cin >> x[i] >> y[i];
    	if (x[i] < 1) {
    		res += 1 - x[i];
    		x[i] = 1; 
    	}
    	if (x[i] > n) {
    		res += x[i] - n;
    		x[i] = n;
    	}
    	if (y[i] < 1) {
    		res += 1 - y[i];
    		y[i] = 1; 
    	}
    	if (y[i] > 2) {
    		res += y[i] - 2; 
            y[i] = 2;
    	}
        cnt[x[i]][y[i]]++; 
    }
    for (int i = 1; i <= n; i++) {
        int change = min(max(0, cnt[i][1] - 1), max(0, 1 - cnt[i][2])); 
        cnt[i][1] -= change;
        cnt[i][2] += change; 
        res += change;
        change = min(max(0, 1 - cnt[i][1]), max(0, cnt[i][2] - 1)); 
        cnt[i][1] += change;
        cnt[i][2] -= change; 
        res += change; 

        res += abs(cnt[i][1] - 1);
        cnt[i + 1][1] += cnt[i][1] - 1; 
        res += abs(cnt[i][2] - 1);
        cnt[i + 1][2] += cnt[i][2] - 1;

    }   
    cout << res;
}

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("OUT.OUT" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...