結果

問題 No.942 プレゼント配り
ユーザー tko919tko919
提出日時 2019-12-08 15:33:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,508 bytes
コンパイル時間 1,711 ms
コンパイル使用メモリ 168,312 KB
実行使用メモリ 9,360 KB
最終ジャッジ日時 2023-08-28 23:04:54
合計ジャッジ時間 3,890 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,228 KB
testcase_01 AC 23 ms
8,636 KB
testcase_02 AC 5 ms
8,224 KB
testcase_03 AC 4 ms
8,160 KB
testcase_04 AC 22 ms
8,892 KB
testcase_05 AC 23 ms
9,360 KB
testcase_06 AC 4 ms
8,112 KB
testcase_07 AC 4 ms
8,332 KB
testcase_08 AC 18 ms
8,696 KB
testcase_09 AC 21 ms
8,792 KB
testcase_10 AC 4 ms
8,124 KB
testcase_11 AC 4 ms
8,104 KB
testcase_12 AC 5 ms
8,224 KB
testcase_13 AC 4 ms
8,060 KB
testcase_14 AC 20 ms
8,672 KB
testcase_15 AC 15 ms
8,520 KB
testcase_16 AC 16 ms
8,720 KB
testcase_17 AC 17 ms
8,508 KB
testcase_18 AC 4 ms
8,208 KB
testcase_19 AC 4 ms
7,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

vector<int> ans[200010];

int main(){
    int n,k; scanf("%d%d",&n,&k);
    int m=n/k;
    if(n==1){
        printf("Yes\n"); puts("1");
        return 0;
    }
    if(((n%2==0)&&m&1)||m==1){printf("No\n"); return 0;}
    printf("Yes\n");
    if(m%2==0){
        int cnt=1;
        rep(i,0,k){
            rep(j,0,m/2){
                ans[i].push_back(cnt); ans[i].push_back(n+1-cnt);
                cnt++;
            }
        }
    }
    else{
        rep(i,0,k)ans[i].resize(3);
        rep(i,0,k)ans[i][0]=i+1;
        int idx=k-1,val=k+1;
        while(idx>=0){
            ans[idx][1]=val; ans[k-1-idx][2]=4*k+1-val;
            idx-=2; val++;
        } idx=k-2;
        while(idx>=0){
            ans[idx][1]=val; ans[k-1-idx][2]=4*k+1-val;
            idx-=2; val++;
        }val=1;
        rep(i,0,k)rep(rot,0,(m-3)/2){
            ans[i].push_back(val+3*k); ans[i].push_back(n+1-val);
            val++;
        }
    }
    rep(i,0,k){
        rep(j,0,m)printf("%d ",ans[i][j]);
        puts("");
    }
    return 0;
}
0