using namespace std;
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
typedef long long ll;
const ll MOD = 1000000007;
ll pow(ll a, ll b){
if(b==0)return (ll)1;
ll n = pow(a,b/2);
if(b%2==0){
return n*n % MOD;
}else{
return n*n*a % MOD;
}
}
void solve(){
int k, n;
cin>>k>>n;
vector<pair<string,int>> vt1;
vector<pair<string,int>> vt2;
vector<int> vt;
if(k==1){
ll sum = 0;
for(int i= 0; i< n; i++) {
string s1, s2;
int a1, a2;
cin >> s1 >> a1 >> s2 >> a2;
if (s1 != s2) {
vt.push_back(a1);
vt.push_back(a2);
}else{
sum+=abs(a1-a2)*2;
}
vt1.push_back({s1, a1});
vt2.push_back({s2, a2});
}
sort(vt.begin(),vt.end());
ll median;
if(!vt.empty()){
median = vt[vt.size()/2]+vt[vt.size()/2-1];
}
for(int i = 0; i < vt.size(); i++){
sum+=abs(median-2*vt[i]);
}
cout<<(sum+vt.size())/2;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
//read(tc);
while(tc--) {
//write("Case #", i+1, ": ");
solve();
}
}
Compilation message
bridge.cpp: In function 'void solve()':
bridge.cpp:140:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for(int i = 0; i < vt.size(); i++){
| ~~^~~~~~~~~~~
bridge.cpp:141:17: warning: 'median' may be used uninitialized in this function [-Wmaybe-uninitialized]
141 | sum+=abs(median-2*vt[i]);
| ~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
50 ms |
10676 KB |
Output is correct |
13 |
Correct |
74 ms |
12212 KB |
Output is correct |
14 |
Correct |
56 ms |
10264 KB |
Output is correct |
15 |
Correct |
42 ms |
7228 KB |
Output is correct |
16 |
Correct |
57 ms |
11700 KB |
Output is correct |
17 |
Correct |
58 ms |
12212 KB |
Output is correct |
18 |
Correct |
65 ms |
11820 KB |
Output is correct |
19 |
Correct |
71 ms |
12212 KB |
Output is correct |
20 |
Correct |
57 ms |
11868 KB |
Output is correct |
21 |
Correct |
65 ms |
11956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |