Submission #369385

#TimeUsernameProblemLanguageResultExecution timeMemory
369385AriaHCoin Collecting (JOI19_ho_t4)C++11
100 / 100
62 ms5996 KiB
/** Im the best because i work as hard as i possibly can **/

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"

const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;

ll pw(ll a , ll b, ll M)  { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }

ll tot;

ll n, A[N][3], cnt[3];

int main()
{
	scanf("%lld", &n);
	for(int i = 1; i <= n << 1; i ++)
	{
		ll x, y; scanf("%lld%lld", &x, &y);
		if(x < 1)
		{
			tot += 1 - x;
			x = 1;
		}
		if(x > n)
		{
			tot += x - n;
			x = n;
		}
		if(y < 1)
		{
			tot += 1 - y;
			y = 1;
		}
		if(y > 2)
		{
			tot += y - 2;
			y = 2;
		}
		A[x][y] ++;
	}
	for(int i = 1; i <= n; i ++)
	{
		cnt[1] += A[i][1] - 1;
		cnt[2] += A[i][2] - 1;
		if(cnt[1] < 0 && cnt[2] > 0)
		{
			ll cu = min(-cnt[1], cnt[2]);
			tot += cu;
			cnt[1] += cu;
			cnt[2] -= cu;
		}
		else if(cnt[2] < 0 && cnt[1] > 0)
		{
			ll cu = min(-cnt[2], cnt[1]);
			tot += cu;
			cnt[2] += cu;
			cnt[1] -= cu;
		}
		tot += abs(cnt[1]);
		tot += abs(cnt[2]);
	}
	printf("%lld\n", tot);
    return 0;
}


Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  scanf("%lld", &n);
      |  ~~~~~^~~~~~~~~~~~
joi2019_ho_t4.cpp:36:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |   ll x, y; scanf("%lld%lld", &x, &y);
      |            ~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...