Submission #1079727

#TimeUsernameProblemLanguageResultExecution timeMemory
1079727_rain_Coin Collecting (JOI19_ho_t4)C++14
100 / 100
42 ms5044 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fixbug true void SETIO(string name = ""){ if (name=="") return; freopen((name+".inp").c_str(),"r",stdin); // freopen((name+".out").c_str(),"w",stdout); return; } const int maxn = 2e5; int in[maxn+2][3] = {} , n; ll ans = 0 , cur[3]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); SETIO(""); cin >> n; ll ans = 0; for (int i = 1; i <= 2*n; ++i) { int x , y; cin >> x >> y; if (x < 1) ans += abs(1 - x) , x = 1; if (x > n) ans += abs(x - n) , x = n; if (y < 1) ans += abs(y - 1) , y = 1; if (y > 2) ans += abs(y - 2) , y = 2; in[x][y]++; } for (int i = 1; i <= n; ++i){ cur[1] += in[i][1] - 1; cur[2] += in[i][2] - 1; if (cur[2] * cur[1] < 0){ ll x = min(abs(cur[2]) , abs(cur[1])); if (cur[2] > 0){ cur[2] -= x; cur[1] += x; ans += x; } else{ cur[2] += x; cur[1] -= x; ans += x; } } ans += abs(cur[2]) + abs(cur[1]); } cout << ans; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'void SETIO(std::string)':
joi2019_ho_t4.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen((name+".inp").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...