Submission #363425

#TimeUsernameProblemLanguageResultExecution timeMemory
363425luciocfPalembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms512 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 1e5+10;

char t[2][maxn];
int pos[2][maxn];

int main(void)
{
	int k, n;
	scanf("%d %d", &k, &n);

	for (int i = 1; i <= n; i++)
		scanf(" %c %d %c %d", &t[0][i], &pos[0][i], &t[1][i], &pos[1][i]);

	if (k == 1)
	{
		ll ans = 0;

		vector<int> v;

		for (int i = 1; i <= n; i++)
		{
			if (t[0][i] == t[1][i]) ans += 1ll*abs(pos[0][i]-pos[1][i]);
			else
			{
				v.push_back(pos[0][i]);
				v.push_back(pos[1][i]);
			}
		}

		int med = v[v.size()/2];

		for (auto x: v)
			ans += 1ll*abs(x-med);

		printf("%lld\n", ans);
	}
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%d %d", &k, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf(" %c %d %c %d", &t[0][i], &pos[0][i], &t[1][i], &pos[1][i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...