Submission #73317978


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, s, e) for (ll i = (ll)(s); i < (ll)(e); ++i)
#define rrep(i, s ,e) for (ll i = (ll)(s); i > (ll)(e); --i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 998244353;
//const ll MOD = 1000000007;

ll H,W,N;
int main(){
    cin.tie(0);cout.tie(0);
    ios_base::sync_with_stdio(false);

    cin >> H >> W >> N;
    int n = N;
    vector<pair<int,int>> v(N);
    rep(i,0,N){
        ll h,w;cin >> h >> w;
        v[i] = {h,w};
    }
    map<int,vector<int>> hm,wm;
    rep(i,0,n){
        hm[v[i].first].emplace_back(i);
        wm[v[i].second].emplace_back(i);
    }
    vector<int> X(N),Y(N);
    int a = 1,b = W,c = 1,d = H;
    ll cnt = 0;
    ll p = 0;
    while(cnt != N){
        p++;
        int w = b-a+1,h = d-c+1;
        for(auto x:hm[h]){
            X[x] = c,Y[x] = a;
            a += v[x].second;
            cnt++;
            if(cnt == N)break;
            w = b-a+1,h = d-c+1;
          
        }
        if(cnt == N)break;
        for(auto x:wm[w]){
            X[x] = c,Y[x] = a;
            c += v[x].first;
            cnt++;
            w = b-a+1,h = d-c+1;
        if(cnt == N)break;
        }
       // if(p == 5)break;
        
    }
    rep(i,0,N){
        cout << X[i] << " " << Y[i] << endl;
    }
}

Submission Info

Submission Time
Task D - Reconstruct Chocolate
User KH8047
Language C++23 (GCC 15.2.0)
Score 425
Code Size 1359 Byte
Status AC
Exec Time 262 ms
Memory 34444 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 2
AC × 19
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_biased_cut_01.txt, 02_biased_cut_02.txt, 02_biased_cut_03.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3656 KiB
00_sample_02.txt AC 1 ms 3656 KiB
01_random_01.txt AC 212 ms 22168 KiB
01_random_02.txt AC 226 ms 24708 KiB
01_random_03.txt AC 147 ms 13972 KiB
01_random_04.txt AC 152 ms 13700 KiB
01_random_05.txt AC 124 ms 10884 KiB
01_random_06.txt AC 120 ms 9864 KiB
01_random_07.txt AC 165 ms 15512 KiB
01_random_08.txt AC 160 ms 14728 KiB
01_random_09.txt AC 129 ms 10636 KiB
01_random_10.txt AC 130 ms 11144 KiB
01_random_11.txt AC 128 ms 11408 KiB
01_random_12.txt AC 123 ms 10640 KiB
01_random_13.txt AC 133 ms 10888 KiB
01_random_14.txt AC 123 ms 10132 KiB
02_biased_cut_01.txt AC 111 ms 9728 KiB
02_biased_cut_02.txt AC 110 ms 9820 KiB
02_biased_cut_03.txt AC 262 ms 34444 KiB