結果

問題 No.609 Noelちゃんと星々
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2020-07-25 14:43:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,454 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 171,828 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-09 12:49:30
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
4,376 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 AC 18 ms
4,384 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 24 ms
4,380 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 34 ms
4,380 KB
testcase_13 RE -
testcase_14 AC 4 ms
4,376 KB
testcase_15 RE -
testcase_16 AC 47 ms
4,380 KB
testcase_17 AC 37 ms
4,376 KB
testcase_18 AC 13 ms
4,376 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:74:25: 警告: ‘k’ may be used uninitialized [-Wmaybe-uninitialized]
   74 |             ll k=(n.at(k/2)+n.at((k/2)-1));
      |                        ~^~
main.cpp:74:16: 備考: ‘k’ はここで定義されています
   74 |             ll k=(n.at(k/2)+n.at((k/2)-1));
      |                ^

ソースコード

diff #

#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;
	}
	
}
0