Submission #73314655


Source Code Expand

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

const int N = 2e5 + 5;
int H,W,n,h[N],w[N];
unordered_map<int,int> cnt_h,cnt_w;
unordered_map<int,vector<int>> pos_h,pos_w;
pair<int,int> ans[N];

void dfs(int now_h,int now_w,int x = 1,int y = 1)
{
	if(cnt_h[now_h])
	{
		int pos = *(--pos_h[now_h].end());
		cnt_h[now_h]--;
		cnt_w[w[pos]]--;
		pos_h[now_h].pop_back();
		pos_w[w[pos]].erase(find(pos_w[w[pos]].begin(),pos_w[w[pos]].end(),pos));
		ans[pos] = {x,y};
		dfs(now_h,now_w - w[pos],x,y + w[pos]);
	}
	else if(cnt_w[now_w])
	{
		int pos = *(--pos_w[now_w].end());
		cnt_w[now_w]--;
		cnt_h[h[pos]]--;
		pos_w[now_w].pop_back();
		pos_h[h[pos]].erase(find(pos_h[h[pos]].begin(),pos_h[h[pos]].end(),pos));
		ans[pos] = {x,y};
		dfs(now_h - h[pos],now_w,x + h[pos],y);
	}
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> H >> W >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> h[i] >> w[i];
		cnt_h[h[i]]++,cnt_w[w[i]]++;
		pos_h[h[i]].push_back(i);
		pos_w[w[i]].push_back(i);
	}
	dfs(H,W);
	for(int i = 1;i <= n;i++)
	{
		int x = ans[i].first,y = ans[i].second;
		cout << x << ' ' << y << "\n";
	}
	return 0;
}

Submission Info

Submission Time
Task D - Reconstruct Chocolate
User world_kiana
Language C++23 (GCC 15.2.0)
Score 425
Code Size 1182 Byte
Status AC
Exec Time 455 ms
Memory 58684 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 3556 KiB
00_sample_02.txt AC 2 ms 3620 KiB
01_random_01.txt AC 325 ms 45780 KiB
01_random_02.txt AC 366 ms 48412 KiB
01_random_03.txt AC 151 ms 33840 KiB
01_random_04.txt AC 149 ms 33840 KiB
01_random_05.txt AC 95 ms 30048 KiB
01_random_06.txt AC 86 ms 28920 KiB
01_random_07.txt AC 237 ms 43076 KiB
01_random_08.txt AC 230 ms 42336 KiB
01_random_09.txt AC 99 ms 29648 KiB
01_random_10.txt AC 102 ms 30300 KiB
01_random_11.txt AC 169 ms 39344 KiB
01_random_12.txt AC 155 ms 38492 KiB
01_random_13.txt AC 167 ms 38800 KiB
01_random_14.txt AC 159 ms 38004 KiB
02_biased_cut_01.txt AC 141 ms 37640 KiB
02_biased_cut_02.txt AC 79 ms 28756 KiB
02_biased_cut_03.txt AC 455 ms 58684 KiB