QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114511 | #4238. Zero Sum | tom0727 | WA | 258ms | 226256kb | C++14 | 4.7kb | 2023-06-22 13:12:44 | 2023-06-22 13:12:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#if __cplusplus >= 201103L
struct pairhash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
template<class T, class U>
size_t operator() (const pair<T,U> &p) const {
static const uint64_t FIXED_RANDOM = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(p.first + FIXED_RANDOM) ^ splitmix64(p.second+ FIXED_RANDOM);
}
};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
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 = (uint64_t)chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
inline int randint(int l, int r) {
return uniform_int_distribution<int>(l,r)(rng);
}
inline double randdouble(double l, double r) {
return uniform_real_distribution<double>(l,r)(rng);
}
inline long long randll(long long l, long long r) {
mt19937_64 rng2((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
return uniform_int_distribution<long long>(l, r)(rng2);
}
#endif
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) 0
#endif
#define fastio ios::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define ll128 __int128_t
#define PI 3.14159265358979323846
#define abs(a) ((a>0)?a:-(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
const long double pi = acos(-1.0);
const long double eps = (double)1e-2;
int mod = (1<<30);
template<class T>
T qpow(T a, int b) {
T res = 1;
while (b) {
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
int norm(int x) {
if (x < 0) {
x += mod;
}
if (x >= mod) {
x -= mod;
}
return x;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
Z(ll x) : x(norm((int)(x % mod))) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(mod - x));
}
Z inv() const {
assert(x != 0);
return qpow(*this, mod - 2);
}
Z &operator*=(const Z &rhs) {
x = (ll)(x) * rhs.x % mod;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
friend std::istream &operator>>(std::istream &is, Z &a) {
ll v;
is >> v;
a = Z(v);
return is;
}
friend std::ostream &operator<<(std::ostream &os, const Z &a) {
return os << a.val();
}
};
const int maxn = 35000+5;
const int maxm = 1e5+55;
const int M = 400;
ll a[maxn][9];
ll dp[maxn][2*M+5];
int n, k;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2*k+1; j++) cin >> a[i][j];
}
vector<int> perm;
for (int i = 1; i <= n; i++) perm.push_back(i);
shuffle(perm.begin(), perm.end(), rng);
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= 2*M+1; j++) {
dp[i][j] = 1e18;
}
}
dp[0][M+1] = 0;
for (int i = 0; i < n; i++) {
int p = perm[i];
for (int j = 1; j <= 2*M+1; j++) {
for (int d = -k; d <= k; d++) {
if (j + d >= 1 && j + d <= 2*M+1) {
dp[i+1][j+d] = min(dp[i+1][j+d], dp[i][j] + a[p][d+k+1]);
}
}
}
}
cout << dp[n][M+1] << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5528kb
input:
3 1 3 14 15 -3 -5 -35 2 71 82
output:
-19
result:
ok 1 number(s): "-19"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5656kb
input:
5 2 1 2 5 14 42 1 2 3 5 8 1 2 4 8 16 1 2 3 4 5 1 2 6 24 120
output:
16
result:
ok 1 number(s): "16"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5608kb
input:
10 2 -904071845 760493887 -478285804 759035367 -680013382 -587322944 665345507 -20509293 103731947 864888628 738633646 936703855 -370523881 301151360 478433861 703775172 -913389861 691762973 -185132991 543994805 -511007159 118916858 891184 349354959 267412081 -663269925 14450557 369277951 237764429 ...
output:
-6259997315
result:
ok 1 number(s): "-6259997315"
Test #4:
score: 0
Accepted
time: 2ms
memory: 7536kb
input:
10 2 -566639283 -281454349 687175663 817449090 928108928 -819788458 -442586076 -451652406 403601435 -168825683 -649266596 187412594 -856159947 476347172 20574258 -390470703 -791341926 -60895976 842388030 507828204 159048971 -531035734 -110061386 255061473 -622553675 767534638 296274618 318355641 -60...
output:
-5863402983
result:
ok 1 number(s): "-5863402983"
Test #5:
score: 0
Accepted
time: 182ms
memory: 226224kb
input:
35000 2 -323024395 123746159 618869974 -455533063 294962647 9971372 784839881 -906564905 -578266269 944975915 968956358 -576765224 448197684 986539127 -525297570 -745293354 426913995 129954892 255813154 -243728523 -922616050 -983803120 -317189892 362753890 481320837 -626411581 760532893 481031139 14...
output:
-23326299571078
result:
ok 1 number(s): "-23326299571078"
Test #6:
score: 0
Accepted
time: 250ms
memory: 226256kb
input:
35000 3 -389986454 -678028773 330282316 582141258 -976039033 415560778 -256794145 891726219 -744524869 671251658 67347457 -91229912 -787543984 364694820 606490044 511500731 766802212 79214055 -745406592 -843185684 -709300461 -806048178 750955329 92731052 -740911920 943335651 -961204999 72788590 5815...
output:
-26267884225753
result:
ok 1 number(s): "-26267884225753"
Test #7:
score: -100
Wrong Answer
time: 258ms
memory: 226236kb
input:
35000 3 -205476456 82285866 -35594070 0 53353652 -49927864 -111238731 113551347 -133551112 19375782 0 -89200221 121851958 207015309 57966468 -78468406 -89972877 0 -14958562 -153791584 207214716 41705397 -138035132 34758504 0 -91078140 3818342 -281759472 199952820 -173442272 -63649020 0 69365700 -761...
output:
-5671328349448
result:
wrong answer 1st numbers differ - expected: '-5671382440154', found: '-5671328349448'