Please sign in first.
Submission #25172730
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
constexpr int Inf = 2000000000;
constexpr long long INF= 2000000000000000000;
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T,typename U>
T modpow(T N, U P, T M = -1){
if(P < 0) return 0;
T ret = 1;
if(M != -1) ret %= M;
while(P) {
if(P & 1) {
if(M == -1) ret *= N;
else ret = ret * N % M;
}
P /= 2;
if(M == -1) N *= N;
else N = N * N % M;
}
return ret;
}
long long MOD = 998244353;
template<typename T>
class SegmentTree {
int N;
const T def;
std::vector<T> dat;
std::function<T(T,T)> operation_;
std::function<T(T,T)> update_;
public:
SegmentTree(int n,T e,std::function<T(T,T)> operation,std::function<T(T,T)> update): def(e),operation_(operation),update_(update) {
int n_ = 1;
while(n > n_) n_ *= 2;
N = n_;
dat = std::vector<T>(2 * N,def);
}
void set(int i,T x) { dat[i + N] = x;}
void build() {
for (int i = N - 1; i >= 1; i--){
dat[i] = operation_(dat[i * 2],dat[i * 2 + 1]);
}
}
void update(int i,T x) {
i += N;
dat[i] = update_(dat[i],x);
while(i > 1) {
i /= 2;
dat[i] = operation_(dat[i * 2],dat[i * 2 + 1]);
}
}
T query(int a,int b) {
int l = a + N;
int r = b + N;
T left_fold = def;
T right_fold = def;
while(l < r) {
if(l & 1) left_fold = operation_(left_fold,dat[l++]);
if(r & 1) right_fold = operation_(dat[--r],right_fold);
l >>= 1;
r >>= 1;
}
return operation_(left_fold,right_fold);
}
T operator[](int i) {return dat[i + N];}
};
int main() {
int N,K;
cin >> N >> K;
vector<int> vec(N);
for(auto& x : vec) cin >> x;
vector<vector<bool>> dp(N + 1,vector<bool>(K));
vector<vector<bool>> dp2(N + 2,vector<bool>(K));
dp[0][0] = true;
dp2[N + 1][0] = true;
for(int i = 0;i < N;i++) {
for(int j = 0;j < K;j++) {
dp[i + 1][j] = (dp[i + 1][j] | dp[i][j]);
if(j >= vec[i]) {
dp[i + 1][j] = (dp[i + 1][j] | dp[i][j - vec[i]]);
}
}
}
for(int i = N + 1;i >= 2;i--) {
for(int j = 0;j < K;j++) {
dp2[i - 1][j] = (dp2[i - 1][j] | dp2[i][j]);
if(j >= vec[i - 2]) {
dp2[i - 1][j] = (dp2[i - 1][j] | dp2[i][j - vec[i - 2]]);
}
}
}
int ret = 0;
for(int i = 0;i < N;i++) {
SegmentTree<bool> seg(K,false,
[](bool a,bool b) {return a || b;},
[](bool a,bool b) {return b;});
for(int j = 0;j < K;j++) {
seg.set(j,dp[i][j]);
}
seg.build();
bool res = false;
for(int j = 0;j < K;j++) {
if(dp2[i + 2][j]) {
if(seg.query(max(K - vec[i] - j,0),K - j)) res = true;
}
}
if(!res) ret++;
}
cout << ret << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - No Need |
| User | AItale |
| Language | C++ (GCC 9.2.1) |
| Score | 600 |
| Code Size | 3400 Byte |
| Status | AC |
| Exec Time | 1973 ms |
| Memory | 9740 KiB |
Compile Error
./Main.cpp: In lambda function:
./Main.cpp:107:41: warning: unused parameter ‘a’ [-Wunused-parameter]
107 | [](bool a,bool b) {return b;});
| ~~~~~^
Judge Result
| Set Name | Sample | Subtask | All | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | 300 / 300 | ||||||
| Status |
|
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 0_000.txt, 0_001.txt, 0_002.txt |
| Subtask | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt |
| All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 0_000.txt | AC | 10 ms | 3520 KiB |
| 0_001.txt | AC | 2 ms | 3592 KiB |
| 0_002.txt | AC | 2 ms | 3532 KiB |
| 1_003.txt | AC | 2 ms | 3392 KiB |
| 1_004.txt | AC | 2 ms | 3552 KiB |
| 1_005.txt | AC | 3 ms | 3436 KiB |
| 1_006.txt | AC | 2 ms | 3536 KiB |
| 1_007.txt | AC | 2 ms | 3420 KiB |
| 1_008.txt | AC | 12 ms | 3448 KiB |
| 1_009.txt | AC | 12 ms | 3520 KiB |
| 1_010.txt | AC | 13 ms | 3504 KiB |
| 1_011.txt | AC | 2 ms | 3564 KiB |
| 1_012.txt | AC | 7 ms | 3588 KiB |
| 1_013.txt | AC | 2 ms | 3644 KiB |
| 1_014.txt | AC | 2 ms | 3492 KiB |
| 1_015.txt | AC | 22 ms | 3516 KiB |
| 1_016.txt | AC | 3 ms | 3556 KiB |
| 1_017.txt | AC | 2 ms | 3592 KiB |
| 1_018.txt | AC | 2 ms | 3588 KiB |
| 1_019.txt | AC | 6 ms | 3420 KiB |
| 1_020.txt | AC | 2 ms | 3484 KiB |
| 1_021.txt | AC | 13 ms | 3556 KiB |
| 1_022.txt | AC | 5 ms | 3440 KiB |
| 1_023.txt | AC | 6 ms | 3568 KiB |
| 1_024.txt | AC | 6 ms | 3628 KiB |
| 1_025.txt | AC | 12 ms | 3568 KiB |
| 2_026.txt | AC | 3 ms | 3556 KiB |
| 2_027.txt | AC | 2 ms | 3560 KiB |
| 2_028.txt | AC | 4 ms | 3336 KiB |
| 2_029.txt | AC | 490 ms | 9600 KiB |
| 2_030.txt | AC | 488 ms | 9688 KiB |
| 2_031.txt | AC | 375 ms | 9708 KiB |
| 2_032.txt | AC | 10 ms | 3780 KiB |
| 2_033.txt | AC | 375 ms | 9596 KiB |
| 2_034.txt | AC | 6 ms | 3780 KiB |
| 2_035.txt | AC | 3 ms | 3808 KiB |
| 2_036.txt | AC | 1973 ms | 9660 KiB |
| 2_037.txt | AC | 7 ms | 3572 KiB |
| 2_038.txt | AC | 6 ms | 3368 KiB |
| 2_039.txt | AC | 7 ms | 3388 KiB |
| 2_040.txt | AC | 422 ms | 8600 KiB |
| 2_041.txt | AC | 976 ms | 6816 KiB |
| 2_042.txt | AC | 1496 ms | 8692 KiB |
| 2_043.txt | AC | 691 ms | 6784 KiB |
| 2_044.txt | AC | 769 ms | 6860 KiB |
| 2_045.txt | AC | 391 ms | 5216 KiB |
| 2_046.txt | AC | 411 ms | 6640 KiB |
| 2_047.txt | AC | 591 ms | 8420 KiB |
| 2_048.txt | AC | 848 ms | 9740 KiB |
| 2_049.txt | AC | 914 ms | 9592 KiB |
| 2_050.txt | AC | 946 ms | 9552 KiB |