Submission #869698

#TimeUsernameProblemLanguageResultExecution timeMemory
869698phamducminhPalembang Bridges (APIO15_bridge)C++17
0 / 100
2 ms604 KiB
//******************/ //* I<3 C++ */ //* I WANT ANY AC */ //* I LOVE PROGRAM!*/ //*IT'S long longERESTING*/ //* I LOVE PROGRAM!*/ //* IN CONTESTS */ //* GET SCORE */ //* AC CODE */ //* LET'S */ //* GO */ //* Written by: */ //* Duc Minh */ #include <bits/stdc++.h> #include <iostream> #include <cmath> #include <vector> #include <map> #include <set> #include <stack> #include <algorithm> #include <string> #include <queue> #include <cctype> #include <cstring> #include <iomanip> #include <deque> using namespace std; #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define all(a) a.begin(),a.end() // #define push_back emplace_back #define endl "\n" #define all1(a) a+1,a+n+1 // #define gcd(a,b) __gcd(a,b); // #define lcm(a,b) (a*b)/gcd(a,b); const long long INF = (long long)1e9; const long long MOD = (long long)1e9+7; const long long MODD = 998244353; const long long maxN = 2e6; // const unsigned unsigned long long du=1000000007; // unsigned unsigned long long w[20],v[20]; // map<unsigned unsigned long long,unsigned unsigned long long> q; // unsigned unsigned long long n,ans=INF; // unsigned unsigned unsigned long long a[200009],pre[200009],x=0,sum=0; // unsigned unsigned long long n,h[1000009],j[1000009],b[1000009]; // unsigned unsigned long long t,n,x,a[1000009]; // unsigned long long t,a[10000009],max1i[10000009],maxin[10000009],maxx=-INF; ///-------------------------------- void solve(); signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // freopen("spath.inp", "r", stdin); // freopen("spath.out", "w", stdout); long long t; // cin >> t; t=1; while (t--){ solve(); } cerr << "Time elapsed: " << TIME << "s.\n"; cerr << "ducminh" << "\n"; return 0; } ///--------------------[PROBLEM SOLUTION]--------------------/// multiset<int> ss; int sum=0,sum1=0,ans=0; void solve(){ int k,n; cin >> k >> n; for (int i=1; i<=n; i++){ char ch1,ch2; int x,y; cin >> ch1 >> x >> ch2 >> y; if (ch1!=ch2) { ss.insert(x); ss.insert(y); sum+=x+y; } else sum1+=2; } int diff=1.0*sum/ss.size(); auto it=ss.lower_bound(diff); int tam=*it; it--; int tam1=*it; if (abs(tam-diff)<abs(tam1-diff)) tam1=tam; else tam=tam1; // cout << tam << "\n"; for (int x: ss){ ans+=abs(tam-x); } ans+=(ss.size()/2); ans+=sum1; cout << ans; }

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:76:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bridge.cpp:77:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...