Submission #148031

#TimeUsernameProblemLanguageResultExecution timeMemory
148031abacabaTreasure (different grader from official contest) (CEOI13_treasure2)C++14
44 / 100
3 ms380 KiB
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <stdio.h>
#include "treasure.h"
#include <assert.h>
#include <string.h>
using namespace __gnu_pbds;
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <random>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <time.h>
using namespace std;

typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>


bool a[105][105];


bool check(int x1, int y1, int x2, int y2, int now, int need) {
	if(now == need) {
		for(int i = x1; i <= x2; ++i)
			for(int j = y1; j <= y2; ++j)
				a[i][j] = 1;
		return true;
	}
	return false;
}

int rec(int x1, int y1, int x2, int y2) {
	if(x1 > x2 || y1 > y2)
		return 0;
	int now = countTreasure(x1, y1, x2, y2);
	if(!now)
		return 0;
	int tot = (x2 - x1 + 1) * (y2 - y1 + 1);
	if(now == (x2 - x1 + 1) * (y2 - y1 + 1)) {
		for(int i = x1; i <= x2; ++i)
			for(int j = y1; j <= y2; ++j)
				a[i][j] = 1;
		return now;
	}
	int sum = 0, midx = x1 + x2 >> 1, midy = y1 + y2 >> 1;
	sum += rec(x1, y1, midx, midy);
	int cur = (midx - x1 + 1) * (midy - y1 + 1);
	bool a = check(midx + 1, y1, x2, midy, now - sum, tot - cur);
	bool b = check(midx + 1, midy + 1, x2, y2, now - sum, tot - cur);
	bool c = check(x1, midy + 1, midx, y2, now - sum, tot - cur);
	if((a && b && c) || sum == now)
		return now;
	sum += rec(midx + 1, y1, x2, midy);
	cur += (midy - y1 + 1) * (x2 - midx);
	if((b && c) || sum == now)
		return now;
	sum += rec(midx + 1, midy + 1, x2, y2);
	cur += (x2 - midx) * (y2 - midy);
	if(c || sum == now)
		return now;
	sum += rec(x1, midy + 1, midx, y2);
	return now;
}

void findTreasure (int N) {
    rec(1, 1, N, N);
    for(int i = 1; i <= N; ++i)
    	for(int j = 1; j <= N; ++j)
    		if(a[i][j])
    			Report(i, j);
}

Compilation message (stderr)

treasure.cpp: In function 'int rec(int, int, int, int)':
treasure.cpp:66:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int sum = 0, midx = x1 + x2 >> 1, midy = y1 + y2 >> 1;
                      ~~~^~~~
treasure.cpp:66:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int sum = 0, midx = x1 + x2 >> 1, midy = y1 + y2 >> 1;
                                           ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...