Submission #1201471

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

#define int long long 
#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 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;
    for (int i = 1; i <= 2 * n; i++) {
    	cin >> x[i] >> y[i];
    }
    sort(x + 1, x + 1 + 2 * n);
    ll res = 0; 
    int cnt = 0; 
    for (int i = 1; i <= 2 * n; i++) {
    	if (y[i] > 2) {
    		res += y[i] - 2;
    		y[i] = 2; 
    	}
    	if (y[i] < 1) {
    		res += 1 - y[i];
    		y[i] = 1; 
    	}	
    	if (y[i] == 2) cnt++; 
    }
    if (cnt < n) cnt = 2 * n - cnt; 
    res += cnt - n; 
    // cout << res;
    for (int i = 1; i <= 2 * n; i++) {
    	int cur = (i + 1) / 2;
    	res += abs(x[i] - cur);
    }
    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...