結果

問題 No.3334 I hate Image Convolution
コンテスト
ユーザー robin dey
提出日時 2025-11-08 05:35:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 137 ms / 3,000 ms
コード長 1,917 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 209,456 KB
実行使用メモリ 14,904 KB
最終ジャッジ日時 2025-11-08 05:35:44
合計ジャッジ時間 24,463 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 56
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define ii pair<ll, ll>
using ll = long long int;
#define pb push_back
#define ss second
#define ff first
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define nl "\n"
#define br cout << "\n";
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
// #define mod 419
// #define mod 1000000007
// #define mod 10000000002065383
const int N = 2e5 + 100;
// const int M = 1000000000;

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 42
#endif

template<typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (auto& elem : v) {
        in >> elem;
    }
    return in;
}

void print(vi &v)
{
    for (auto x : v)
        cout << x << " ";
    cout << endl;
}

/*
    if even >= 2 print even[0] even[1]
    
    for: odds>1:


*/


void solve() {
    ll n,cur=0; cin >> n; 
    vi v((n-1)*(n-1)); cin >> v; 
    sort(all(v));

    vector<vector<ll>> b(n-1, vector<ll>(n-1));
    rep(i,0,n-1) rep(j,0,n-1) b[i][j] = v[cur++];
    
    rep(i,0,n-1){
        if(i&1) sort(rall(b[i]));
        else sort(all(b[i]));
    }
    debug(b);
    
    vector<vector<ll>> a(n, vector<ll>(n));

    rep(i,1,n){
        if(i&1){
            rep(j,1,n){
                a[i][j] = b[i-1][j-1] - a[i-1][j-1] - a[i-1][j] - a[i][j-1];  
            }
        }else{
            for(ll j = n-2; j>=0 ;j--){
                a[i][j] = b[i-1][j] - a[i-1][j+1] - a[i-1][j] - a[i][j+1];  
            }
        }
    }
    
    rep(i,0,n){
        rep(j,0,n){
            cout << a[i][j] << " ";
        }
        cout << nl;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int Test = 1;
    cin >> Test;

    while (Test--) 
    {
        solve();
    }
    return 0;
}
0