提出 #59213386
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using P=pair<int,int>;
using vi=vc<int>;
#define SIZE 32
bool dp[SIZE][SIZE][SIZE*SIZE];
void solve(){
int n,q;
cin>>n>>q;
for(int h=1;h<=n;h++){
for(int w=1;w<=n;w++){
for(int x=0;x<=h*w;x++){
if(h==1||w==1){
dp[h][w][x]=(x==h*w);
} else{
dp[h][w][x]=(x==0);
if(x>=h) dp[h][w][x]|=dp[h][w-1][x-h];
if(x>=w) dp[h][w][x]|=dp[h-1][w][x-w];
}
}
for(int a=1;a<h;a++){
for(int b=1;b<w;b++){
int c=a*b+(h-a)*(w-b);
for(int z=0;z<=a*(w-b);z++){
if(dp[a][w-b][z]){
for(int y=0;y<=(h-a)*b;y++){
dp[h][w][c+z+y]|=dp[h-a][b][y];
}
}
}
}
}
}
}
for(int i=0;i<q;i++){
int c;
cin>>c;
cout<<(dp[n][n][c]?"Yes":"No")<<endl;
}
}
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
int T=1;
while(T--) solve();
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | A - Underclued |
| ユーザ | yutaka1999 |
| 言語 | C++ 23 (Clang 16.0.6) |
| 得点 | 900 |
| コード長 | 1680 Byte |
| 結果 | AC |
| 実行時間 | 150 ms |
| メモリ | 4364 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 900 / 900 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, sample_01.txt, sample_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 02.txt | AC | 1 ms | 3392 KiB |
| 03.txt | AC | 1 ms | 3408 KiB |
| 04.txt | AC | 1 ms | 3596 KiB |
| 05.txt | AC | 1 ms | 3548 KiB |
| 06.txt | AC | 1 ms | 3572 KiB |
| 07.txt | AC | 1 ms | 3448 KiB |
| 08.txt | AC | 1 ms | 3452 KiB |
| 09.txt | AC | 1 ms | 3564 KiB |
| 10.txt | AC | 1 ms | 3572 KiB |
| 11.txt | AC | 1 ms | 3460 KiB |
| 12.txt | AC | 1 ms | 3564 KiB |
| 13.txt | AC | 2 ms | 3604 KiB |
| 14.txt | AC | 2 ms | 3636 KiB |
| 15.txt | AC | 3 ms | 3596 KiB |
| 16.txt | AC | 4 ms | 3828 KiB |
| 17.txt | AC | 5 ms | 3764 KiB |
| 18.txt | AC | 7 ms | 3940 KiB |
| 19.txt | AC | 10 ms | 3836 KiB |
| 20.txt | AC | 13 ms | 3888 KiB |
| 21.txt | AC | 18 ms | 3960 KiB |
| 22.txt | AC | 23 ms | 3892 KiB |
| 23.txt | AC | 30 ms | 3960 KiB |
| 24.txt | AC | 38 ms | 4076 KiB |
| 25.txt | AC | 50 ms | 4096 KiB |
| 26.txt | AC | 62 ms | 4148 KiB |
| 27.txt | AC | 80 ms | 4152 KiB |
| 28.txt | AC | 99 ms | 4364 KiB |
| 29.txt | AC | 124 ms | 4316 KiB |
| 30.txt | AC | 150 ms | 4288 KiB |
| sample_01.txt | AC | 1 ms | 3500 KiB |
| sample_02.txt | AC | 122 ms | 4292 KiB |