結果

問題 No.942 プレゼント配り
ユーザー tarattata1tarattata1
提出日時 2019-12-05 01:25:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 2,000 ms
コード長 2,922 bytes
コンパイル時間 1,385 ms
コンパイル使用メモリ 86,584 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-21 11:43:20
合計ジャッジ時間 3,229 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 18 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 19 ms
4,376 KB
testcase_05 AC 18 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 17 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 17 ms
4,380 KB
testcase_15 AC 12 ms
4,380 KB
testcase_16 AC 14 ms
4,376 KB
testcase_17 AC 13 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n,K;
    scanf("%d%d", &n, &K);

    if(K==1) {
        printf("Yes\n");
        int i;
        for(i=0; i<n; i++) {
            printf("%d ", i+1);
        }
        printf("\n");
        return 0;
    }

    int m=n/K;
    if(K%2==0 && m%2) {
        printf("No\n"); return 0;
    }
    else if(K%2==0 || m%2==0) {
        printf("Yes\n");
        vector<vector<int> > z(K);
        int i,j;
        int cnt=0;
        for(i=0; i<m; i++) {
            for(j=0; j<K; j++) {
                int j2=(i%2==0? j: K-1-j);
                z[j2].push_back(cnt+1);
                cnt++;
            }
        }
        for(i=0; i<K; i++) {
            for(j=0; j<m; j++) {
                printf("%d ", z[i][j]);
            }
            printf("\n");
        }
    }
    else {
        if(m<=2) {
            printf("No\n"); return 0;
        }
        else {
            printf("Yes\n");
            vector<vector<int> > z(K);
            int i,j;
            int cnt=0;
            for(i=0; i<m; i++) {
                if(i<m-2) {
                    for(j=0; j<K; j++) {
                        int j2=(i%2==0? j: K-1-j);
                        z[j2].push_back(cnt+1);
                        cnt++;
                    }
                }
                else if(i==m-2) {
                    int K0=(K-1)/2;
                    for(j=0; j<K; j++) {
                        int j1;
                        if(j<K0) j1=K0-1-j;
                        else j1=K0*3-j;
                        int j2=(i%2==0? j1: K-1-j1);
                        z[j2].push_back(cnt+1);
                        cnt++;
                    }
                }
                else {
                    vector<pair<int,int> > v;
                    int p;
                    for(p=0; p<K; p++) {
                        int tmp=z[p][m-3]+z[p][m-2];
                        v.push_back(make_pair(tmp,p));
                    }
                    sort(v.rbegin(), v.rend());
                    for(j=0; j<K; j++) {
                        z[v[j].second].push_back(cnt+1);
                        cnt++;
                    }
                }
            }
            for(i=0; i<K; i++) {
                for(j=0; j<m; j++) {
                    printf("%d ", z[i][j]);
                }
                printf("\n");
            }
        }
    }


    return 0;
}
0