結果
問題 | No.609 Noelちゃんと星々 |
ユーザー |
![]() |
提出日時 | 2020-07-25 14:43:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,454 bytes |
コンパイル時間 | 1,807 ms |
コンパイル使用メモリ | 171,912 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 05:52:01 |
合計ジャッジ時間 | 5,307 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 RE * 15 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:74:25: warning: 'k' may be used uninitialized [-Wmaybe-uninitialized] 74 | ll k=(n.at(k/2)+n.at((k/2)-1)); | ~^~ main.cpp:74:16: note: 'k' was declared here 74 | ll k=(n.at(k/2)+n.at((k/2)-1)); | ^
ソースコード
#include <iostream> #include <random> #include <bits/stdc++.h> using namespace std; using ull = __int128; using ll = long long; std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } __int128 p(string &s) { __int128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } ll gcd(ll a,ll b) { if (a%b == 0) { return(b); } else { return(gcd(b, a%b)); } } ll z(ll a,ll b){ if(a<b){ swap(a,b); return z(a,b); } else{ return a-b; } } int main(){ ll a; cin>>a; vector<ll> n(a); for(int i=0;i<a;i++){ cin>>n.at(i); } sort(n.begin(), n.end()); if(a%2==1){ ll k=n.at((a-1)/2); ll ans=0; for(int i=0;i<a;i++){ ans=ans+z(k,n.at(i)); } cout<<ans<<endl; } else{ ll k=(n.at(k/2)+n.at((k/2)-1)); ll ans=0; for(int i=0;i<a;i++){ ans=ans+z(k,n.at(i)); } cout<<ans<<endl; } }