Submission #456191

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
4561912021-08-06 08:41:00nonsensenonsense1Palembang Bridges (APIO15_bridge)C++17
22 / 100
53 ms3456 KiB
#include <cstdio>
#include <algorithm>
#include <vector>
const int N = 100000;
int n, task;
std::vector<int> a;
int main()
{
scanf("%d%d", &task, &n);
long long ans_add = 0;
for (int i = 0; i < n; ++i) {
char type1, type2;
int l, r;
scanf(" %c%d %c%d", &type1, &l, &type2, &r);
if (l > r) std::swap(l, r);
if (type1 == type2) ans_add += r - l;
else {
++ans_add;
a.push_back(l);
a.push_back(r);
}
}
std::sort(a.begin(), a.end());
long long ans = 0;
for (int i = 0; i < (int)a.size() / 2; ++i) ans += a[a.size() / 2] - a[i];
for (int i = (int)a.size() / 2; i < (int)a.size(); ++i) ans += a[i] - a[a.size() / 2];
printf("%lld\n", ans_add + ans);
return 0;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d", &task, &n);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
bridge.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf(" %c%d %c%d", &type1, &l, &type2, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...