結果

問題 No.2835 Take and Flip
ユーザー 4094706840947068
提出日時 2024-08-09 21:28:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 2,605 bytes
コンパイル時間 3,724 ms
コンパイル使用メモリ 193,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-08-09 21:28:49
合計ジャッジ時間 5,871 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 82 ms
5,376 KB
testcase_04 AC 87 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 94 ms
5,376 KB
testcase_07 AC 95 ms
5,376 KB
testcase_08 AC 78 ms
5,376 KB
testcase_09 AC 93 ms
5,376 KB
testcase_10 AC 94 ms
5,376 KB
testcase_11 AC 90 ms
5,376 KB
testcase_12 AC 89 ms
5,376 KB
testcase_13 AC 91 ms
5,376 KB
testcase_14 AC 37 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 59 ms
5,376 KB
testcase_17 AC 8 ms
5,376 KB
testcase_18 AC 71 ms
5,376 KB
testcase_19 AC 88 ms
5,376 KB
testcase_20 AC 33 ms
5,376 KB
testcase_21 AC 84 ms
5,376 KB
testcase_22 AC 62 ms
5,376 KB
testcase_23 AC 29 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<algorithm>
#include<deque>
#include<list>
#include<map>
#include<memory>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<string.h>
#include<string>
#include<math.h>
#include<float.h>
#include<stdio.h>
#include<vector>
#include<iomanip>
#include<bitset>
#include<random>
#include"atcoder/all"
#include"atcoder/modint"
using namespace std;
using namespace atcoder;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T &a, T b) { return ((a>b) ? (a = b, true) : (false));}
#define rep(i,s,n) for(long long i=s;i<(long long)(n);i++)
#define rrep(i,s,n) for(long long i=n-1;i>=s;i--)
const long long inf = 1LL<<60;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//pairのsecondでソートsort(p.begin(),p.end(),cmp)
#define cmp [](pair<ll,ll> a, pair<ll,ll> b){return a.second<b.second;}
//cmpArg := 偏角ソート, atan2l(y, x);
#define cmpArg [](const auto &p1, const auto &p2) { return atan2l(p1.second, p1.first) < atan2l(p2.second, p2.first); }
typedef pair<long long, long long> P;
typedef pair<ll, pair<ll,ll> > PP;
#define rll ll,vector<ll>,greater<ll>
#define rP P,vector<P>,greater<P>
const long double pi = 3.14159265358979;
typedef unsigned long long ull;
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vmint vector<mint>
#define vvmint vector<vector<mint>>
#define vvch vector<vector<char>>
#define vch vector<char>
#define vstring vector<string>
#define rPP PP,vector<PP>,greater<PP>
#define vP vector<P> 
#define vvP vector<vector<P>>
#define vPP vector<PP>
#define all(x) x.begin(), x.end()
//UNIQUE(x) xをソートして値の被りがないようにする
#define UNIQUE(x) sort(all(x)), x.erase(unique(all(x)), x.end())
int stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); } //sに含まれるcの数
int pc(int x) { return __builtin_popcount(x); } //ビット列にどれだけ1がたっているかを求める pop count
//オバフロしない計算はa > inf - b および a > inf / bでとってね

using mint = modint998244353;

int main()
{
    int n; cin >> n;
    vll a(n); rep(i,0,n) cin >> a[i];
    sort(all(a));

    int turn = 0;
    ll ans = 0;
    int powm1[202020]; powm1[0] = 1; rep(i,1,202020) powm1[i] = powm1[i-1] * (-1);
    int l = 0, r = n-1;
    while(r - l >= 0) {
        if(turn == 0) {
            ans += a[r];
            r--;
        }
        else {
            ans += a[l];
            l++;
        }
    }
    cout << ans << endl;
}
0