이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define cIO ios_base::sync_with_stdio(0);cin.tie(0)
#define fileIO(x) ifstream fin(string(x)+".in"); ofstream fout(string(x)+".out")
#define cont(container, object) (container.find(object)!=container.end())
#define sz(x) (int) (x).size()
#define ll long long
#define v vector
int ppl_cvr[1 << 20], leftover[1 << 20];
int N, M;
int main()
{
fill_n(ppl_cvr, 1 << 20, -1);
fill_n(leftover, 1 << 20, 0);
cin >> N >> M;
vector<int> ppl(N, 0);
vector<int> notes(M, 0);
for (int i = 0; i <= N - 1; i++) cin >> ppl[i];
ppl.push_back(10000000);//to prevent overflow
for (int i = 0; i <= M - 1; i++) cin >> notes[i];
for (int msk = 1; msk < (1 << M); msk++)
{
for (int nt = 0; nt <= M - 1; nt++)
{
if (msk & (1 << nt))
{
if (ppl[ppl_cvr[msk - (1 << nt)] + 1]
== notes[nt] + leftover[msk - (1 << nt)])//if exactly enough for the next person
{
ppl_cvr[msk] = max(ppl_cvr[msk], ppl_cvr[msk - (1 << nt)] + 1);
leftover[msk] = 0;
}
else
{
ppl_cvr[msk] = max(ppl_cvr[msk], ppl_cvr[msk - (1 << nt)]);
leftover[msk] = leftover[msk - (1 << nt)] + notes[nt];
}
}
}
}
if (ppl_cvr[(1 << M) - 1] == N - 1) cout << "YES";
else cout << "NO";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |