結果

問題 No.1988 Divisor Tiling
ユーザー みここ
提出日時 2022-06-24 21:34:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 64,384 KB
実行使用メモリ 35,840 KB
最終ジャッジ日時 2024-11-08 17:29:02
合計ジャッジ時間 2,359 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int d[10005][10005];

int main()
{
    int n, h;
    cin >> n >> h;
    int w = n / h;
    for(int u = n - 1; u > 0; u--)
    {
        if(n % u == 0)
        {
            if(u % h == 0)
            {
                int l = w - u / h;
                for(int i = 0; i < h; i++)
                {
                    for(int j = l; j < w; j++)
                    {
                        d[i][j] = u;
                    }
                }
                w = l;
            }
            else if(u % w == 0)
            {
                int l = h - u / w;
                for(int i = l; i < h; i++)
                {
                    for(int j = 0; j < w; j++)
                    {
                        d[i][j] = u;
                    }
                }
                h = l;
            }
            else
            {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        if(d[i][0] == 0)
        {
            break;
        }
        for(int j = 0; j < n; j++)
        {
            if(d[i][j] == 0)
            {
                cout << endl;
                break;
            }
            cout << d[i][j] << " ";
        }
    }
}
0