Submission #75065150


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "../../Templates/C++/debug.h"
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define lso(s) ((s) & -(s))
int lg(ll s) { return s ? __builtin_clzll(1) - __builtin_clzll(s) : -1; }//lg(1)=0, lg(2)=1, lg(3)=1, lg(4)=2, ...
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MOD = 998244353;
const double EPS = 1e-9;
const char nl = '\n';
const int INF = 1e9;
const ll INFL = 4e18;
ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b, a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll floor(ll a, ll b) { return a / b - (a % b < 0); }
ll ceil(ll a, ll b) { return a / b + (a % b > 0); }

template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937_64 rng(10);//rng(chrono::steady_clock::now().time_since_epoch().count());
ll gen() {
	ll x = 0;
	while(x == 0)
		x = rng() % MOD;
	return x;
}

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}


void solve() {
    int N; cin >> N;
    int M; cin >> M;
    vi v(N); cin >> v;
    vi d(N - 1);
    for(int i = 0; i < N - 1; i++) {
        d[i] = (v[i + 1] - v[i] + M) % M;
    }

    vl vec;
    ll tot = 0;
    if(!(N & 1)) {
        tot = d[N / 2 - 1];
        vec.pb(tot);
    }
    debug(d);
    for(int i = N / 2; i < N - 1; i++) {
        int j = N - i - 2;
        // debug(d[i], d[j]);
        vec.pb((d[i] + d[j]) % M);
    }
    debug(vec);

    sort(all(vec));
    vl pf(sz(vec) + 1);
    for(int i = 0; i < sz(vec); i++) pf[i + 1] = pf[i] + vec[i];
    vl sf(sz(vec) + 1);
    for(int i = sz(vec) - 1; i >= 0; i--) sf[i] = sf[i + 1] + (M - vec[i]);

    debug(pf, sf);
    ll ans = INFL;
    for(int i = 0; i < sz(vec) + 1; i++) {
        ans = min(ans, max(sf[i], pf[i]));
    }
    cout << ans << nl;

}
/*
0 3 1 2

0 3 3 1 2

3 1 4 1 5 9 2

10 3 9 4 4 5
*/


int main() {
    //魔法はイメージの世界
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
	return 0;
}

Submission Info

Submission Time
Task F - Make it Palindrome 2
User YuukiS18
Language C++23 (GCC 15.2.0)
Score 525
Code Size 4181 Byte
Status AC
Exec Time 35 ms
Memory 7452 KiB

Compile Error

./Main.cpp: In function 'void solve()':
./Main.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
./Main.cpp:121:5: note: in expansion of macro 'debug'
  121 |     debug(d);
      |     ^~~~~
./Main.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
./Main.cpp:127:5: note: in expansion of macro 'debug'
  127 |     debug(vec);
      |     ^~~~~
./Main.cpp:7:20: warning: statement has no effect [-Wunused-value]
    7 | #define debug(...) 42
      |                    ^~
./Main.cpp:135:5: note: in expansion of macro 'debug'
  135 |     debug(pf, sf);
      |     ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3432 KiB
01_handmade_00.txt AC 11 ms 7416 KiB
01_handmade_01.txt AC 13 ms 3596 KiB
01_handmade_02.txt AC 12 ms 7444 KiB
01_handmade_03.txt AC 12 ms 7388 KiB
01_handmade_04.txt AC 12 ms 7328 KiB
02_random_00.txt AC 14 ms 6448 KiB
02_random_01.txt AC 17 ms 7452 KiB
02_random_02.txt AC 2 ms 3880 KiB
02_random_03.txt AC 17 ms 7344 KiB
02_random_04.txt AC 3 ms 4080 KiB
02_random_05.txt AC 17 ms 7364 KiB
02_random_06.txt AC 17 ms 7212 KiB
02_random_07.txt AC 17 ms 7332 KiB
02_random_08.txt AC 9 ms 5360 KiB
02_random_09.txt AC 18 ms 7404 KiB
02_random_10.txt AC 35 ms 3572 KiB
02_random_11.txt AC 22 ms 3612 KiB
02_random_12.txt AC 14 ms 3500 KiB
02_random_13.txt AC 14 ms 3568 KiB
02_random_14.txt AC 12 ms 3544 KiB
02_random_15.txt AC 13 ms 3600 KiB
02_random_16.txt AC 14 ms 3744 KiB
02_random_17.txt AC 13 ms 3744 KiB