제출 #979798

#제출 시각아이디문제언어결과실행 시간메모리
979798c2zi6Hexagonal Territory (APIO21_hexagon)C++14
20 / 100
121 ms197476 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "hexagon.h"

const ll MOD = 1e9 + 7;

namespace TEST2 {
	ll binpow(ll a, ll b) {
		if (b == 0) return 1;
		if (b & 1) return a*binpow(a, b-1) % MOD;
		ll ret = binpow(a, b/2);
		return ret*ret % MOD;
	}
	ll inv(ll x) {
		return binpow(x, MOD-2);
	}
	ll sum(ll n) {
		return n*(n+1) % MOD * inv(2) % MOD;
	}
	ll sumsq(ll n) {
		return n * (2*n+1) % MOD * (n+1) % MOD * inv(6) % MOD;
	}
	int solve(int n, int A, int B, VI D, VI L) {
		ll x = L[0]+1;
		ll mas1 = sum(x) * A % MOD;
		ll mas2 = (sumsq(x) + MOD-sum(x))%MOD * B % MOD;
		return (mas1 + mas2) % MOD;
	}
}

namespace TEST3 {
	int table[5000][5000];
	int dist[5000][5000];
	VPI harevan(int i, int j) {
		VPI ret;
		ret.pb({i-1, j});
		ret.pb({i, j+1});
			ret.pb({i+1, j+1});
		ret.pb({i+1, j});
		ret.pb({i, j-1});
			ret.pb({i-1, j-1});
		return ret;
	}
	void dfs(int i, int j) {
		table[i][j] = 3;
		for (auto[vi, vj] : harevan(i, j)) if (table[vi][vj] == 2) {
			dfs(vi, vj);
		}
	}
	int solve(int n, int A, int B, VI D, VI L) {
		int ui = 2500, uj = 2500;
		rep(i, n) {
			int dir = D[i]-1;
			rep(j, L[i]) {
				auto[vi, vj] = harevan(ui, uj)[dir];
				table[ui][uj] = 1;
				ui = vi;
				uj = vj;
			}
		}
		int lmi, lmj = 1e9;
		replr(i, 1, 4998) replr(j, 1, 4998) if (table[i][j] == 1) {
			for (auto[vi, vj] : harevan(i, j)) {
				if (table[vi][vj] == 1) continue;
				if (vj < lmj) {
					lmi = vi;
					lmj = vj;
				}
				table[vi][vj] = 2;
			}
		}
		dfs(lmi, lmj);
		replr(i, 1, 4998) replr(j, 1, 4998) if (table[i][j] < 3) table[i][j] = 0;
		replr(i, 0, 4999) replr(j, 0, 4999) dist[i][j] = 2e9;
		queue<PII> q;
		q.push({2500, 2500});
		dist[2500][2500] = 0;
		VI ans{0};
		while (q.size()) {
			auto[ui, uj] = q.front();
			q.pop();
			for (auto[vi, vj] : harevan(ui, uj)) if (table[vi][vj] == 0 && dist[vi][vj] == 2e9) {
				dist[vi][vj] = dist[ui][uj]+1;

				ans.pb(dist[vi][vj]);

				q.push({vi, vj});
			}
		}
		ll ret = 0;
		for (int x : ans) {
			ll cur = (A + 1ll * x * B) % MOD;
			ret += cur;
			ret %= MOD;
		}
		return ret;
	}
}


int draw_territory(int n, int A, int B, VI D, VI L) {
	if (n == 3) return TEST2::solve(n, A, B, D, L);
	return TEST3::solve(n, A, B, D, L);
}

컴파일 시 표준 에러 (stderr) 메시지

hexagon.cpp: In function 'void TEST3::dfs(int, int)':
hexagon.cpp:75:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   75 |   for (auto[vi, vj] : harevan(i, j)) if (table[vi][vj] == 2) {
      |            ^
hexagon.cpp: In function 'int TEST3::solve(int, int, int, VI, VI)':
hexagon.cpp:84:9: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   84 |     auto[vi, vj] = harevan(ui, uj)[dir];
      |         ^
hexagon.cpp:92:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   92 |    for (auto[vi, vj] : harevan(i, j)) {
      |             ^
hexagon.cpp:109:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  109 |    auto[ui, uj] = q.front();
      |        ^
hexagon.cpp:111:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  111 |    for (auto[vi, vj] : harevan(ui, uj)) if (table[vi][vj] == 0 && dist[vi][vj] == 2e9) {
      |             ^
hexagon.cpp:101:6: warning: 'lmi' may be used uninitialized in this function [-Wmaybe-uninitialized]
  101 |   dfs(lmi, lmj);
      |   ~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...