Submission #67383199
Source Code Expand
/**
* author: otera
**/
#include<bits/stdc++.h>
namespace otera {}
using namespace std;
using namespace otera;
struct io_setup {
io_setup(int precision = 20) {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(precision);
}
} io_setup_ {};
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
#define repa(i, n) for(int i = 0; i < (n); ++ i)
#define repb(i, a, b) for(int i = (a); i < (b); ++ i)
#define repc(i, a, b, c) for(int i = (a); i < (b); i += (c))
#define overload4(a, b, c, d, e, ...) e
#define overload3(a, b, c, d, ...) d
#define rep(...) overload4(__VA_ARGS__, repc, repb, repa)(__VA_ARGS__)
#define rep1a(i, n) for(int i = 1; i <= (n); ++ i)
#define rep1b(i, a, b) for(int i = (a); i <= (b); ++ i)
#define rep1c(i, a, b, c) for(int i = (a); i <= (b); i += (c))
#define rep1(...) overload4(__VA_ARGS__, rep1c, rep1b, rep1a)(__VA_ARGS__)
#define rev_repa(i, n) for(int i=(n)-1;i>=0;i--)
#define rev_repb(i, a, b) for(int i=(b)-1;i>=(a);i--)
#define rev_rep(...) overload3(__VA_ARGS__, rev_repb, rev_repa)(__VA_ARGS__)
#define rev_rep1a(i, n) for(int i=(n);i>=1;i--)
#define rev_rep1b(i, a, b) for(int i=(b);i>=(a);i--)
#define rev_rep1(...) overload3(__VA_ARGS__, rev_rep1b, rev_rep1a)(__VA_ARGS__)
#define for_subset(t, s) for(ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define mkp make_pair
#define mkt make_tuple
#define fr first
#define sc second
#define all(c) std::begin(c), std::end(c)
#define rall(c) std::rbegin(c), std::rend(c)
#define lb(c, x) distance(std::begin(c), lower_bound(all(c), (x)))
#define ub(c, x) distance(std::begin(c), upper_bound(all(c), (x)))
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));(a).erase(unique(all(a)),std::end(a))
#define si(c) (int)(c).size()
inline ll popcnt(ull a){ return __builtin_popcountll(a); }
#define kth_bit(x, k) ((x>>k)&1)
#define unless(A) if(!(A))
#define elif else if
ll modulo(ll n, ll d){ return (n % d + d) % d; };
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll intpow(ll a, ll b, ll m) {ll ans = 1; while(b){ if(b & 1) (ans *= a) %= m; (a *= a) %= m; b /= 2; } return ans; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <typename T> constexpr inline int pow_m1(T n) { return -(n & 1) | 1; }
template <typename T> constexpr inline T fld(const T x, const T y) { return (x ^ y) >= 0 ? x / y : (x - (y + pow_m1(y >= 0))) / y; }
template <typename T> constexpr inline T cld(const T x, const T y) { return (x ^ y) <= 0 ? x / y : (x + (y + pow_m1(y >= 0))) / y; }
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type>name(__VA_ARGS__)
#define VEC(type,name,size) vector<type>name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vc<T>>;
template <class T> using vvvc = vector<vvc<T>>;
template <class T> using vvvvc = vector<vvvc<T>>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template<class T> void scan(T& a){ cin >> a; }
template<class T> void scan(vector<T>& a){ for(auto&& i : a) scan(i); }
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){ scan(head); in(tail...); }
void print(){ cout << ' '; }
template<class T> void print(const T& a){ cout << a; }
template<class T> void print(const vector<T>& a){ if(a.empty()) return; print(a[0]); for(auto i = a.begin(); ++i != a.end(); ){ cout << ' '; print(*i); } }
int out(){ cout << '\n'; return 0; }
template<class T> int out(const T& t){ print(t); cout << '\n'; return 0; }
template<class Head, class... Tail> int out(const Head& head, const Tail&... tail){ print(head); cout << ' '; out(tail...); return 0; }
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#define dump(...) { print(#__VA_ARGS__); print(":"); out(__VA_ARGS__); }
#else
#define debug(...)
#define dump(...)
#endif
int n, m;
vc<string> s;
vc<P> final_ans;
const int inf = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
bool inside(int x, int y) {
return 0 <= x and x < n and 0 <= y and y < n;
}
void init() {
in(n, m);
s.resize(n);
rep(i, n) {
in(s[i]);
}
}
void output() {
int sz = si(final_ans);
assert(sz == n * n - m);
rep(i, sz) {
out(final_ans[i].fr, final_ans[i].sc);
}
}
void solver1() {
int sz = n * n - m;
auto check = [&](int x, int y) -> bool {
rep(k, 4) {
int nx = x + dx[k], ny = y + dy[k];
if(!inside(nx, ny) or s[nx][ny] == '#') {
return false;
}
}
return true;
};
rep(_, sz) {
int flag = 0;
rep(x, n) {
rep(y, n) {
if(!flag and s[x][y] == '.' and check(x, y)) {
flag = 1;
final_ans.eb(x, y);
s[x][y] = '#';
}
}
}
rep(x, n) {
rep(y, n) {
if(!flag and s[x][y] == '.') {
flag = 1;
final_ans.eb(x, y);
s[x][y] = '#';
}
}
}
}
}
void solver2() {
int sz = n * n - m;
vvc<ld> dp(n, vc<ld>(n, 0.0));
rep(x, n) {
rep(y, n) {
dp[x][y] = 1.0 / (ld)(n * n);
}
}
vvc<int> g_x(n), g_y(n);
rep(x, n) {
g_x[x].eb(-1);
g_x[x].eb(n);
}
rep(y, n) {
g_y[y].eb(-1);
g_y[y].eb(n);
}
rep(x, n) {
rep(y, n) {
if(s[x][y] == '.') continue;
g_x[x].eb(y);
g_y[y].eb(x);
}
}
rep(x, n) Sort(g_x[x]);
rep(y, n) Sort(g_y[y]);
rep(_, sz) {
ld cur = inf;
int pos_x = -1, pos_y = -1;
rep(x, n) {
rep(y, n) {
if(s[x][y] == '#') continue;
if(chmin(cur, dp[x][y])) {
pos_x = x, pos_y = y;
}
}
}
assert(pos_x != -1 and pos_y != -1);
assert(s[pos_x][pos_y] == '.');
s[pos_x][pos_y] = '#';
dp[pos_x][pos_y] = 0.0;
final_ans.eb(pos_x, pos_y);
g_x[pos_x].eb(pos_y);
g_y[pos_y].eb(pos_x);
Sort(g_x[pos_x]);
Sort(g_y[pos_y]);
vvc<ld> ndp(n, vc<ld>(n, 0.0));
auto nxt = [&](int x, int y) -> vc<P> {
vc<P> ret;
{
int id = ub(g_x[x], y);
// assert(1 <= id and id < si(g_x[x]));
ret.eb(x, g_x[x][id - 1] + 1);
ret.eb(x, g_x[x][id] - 1);
}
{
int id = ub(g_y[y], x);
// assert(1 <= id and id < si(g_y[y]));
ret.eb(g_y[y][id - 1] + 1, y);
ret.eb(g_y[y][id] - 1, y);
}
return ret;
};
rep(x, n) {
rep(y, n) {
if(s[x][y] == '#') continue;
vc<P> ns = nxt(x, y);
for(auto [nx, ny]: ns) {
assert(inside(nx, ny));
ndp[nx][ny] += dp[x][y] / (ld)4.0;
}
}
}
swap(dp, ndp);
}
}
void solve() {
init();
solver2();
output();
}
signed main() {
int testcase = 1;
// in(testcase);
while(testcase--) solve();
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Gamble on Ice |
User |
otera |
Language |
C++ 20 (gcc 12.2) |
Score |
136954024 |
Code Size |
9336 Byte |
Status |
AC |
Exec Time |
92 ms |
Memory |
3740 KiB |
Judge Result
Set Name |
test_ALL |
Score / Max Score |
136954024 / 150000000 |
Status |
|
Set Name |
Test Cases |
test_ALL |
test_0000.txt, test_0001.txt, test_0002.txt, test_0003.txt, test_0004.txt, test_0005.txt, test_0006.txt, test_0007.txt, test_0008.txt, test_0009.txt, test_0010.txt, test_0011.txt, test_0012.txt, test_0013.txt, test_0014.txt, test_0015.txt, test_0016.txt, test_0017.txt, test_0018.txt, test_0019.txt, test_0020.txt, test_0021.txt, test_0022.txt, test_0023.txt, test_0024.txt, test_0025.txt, test_0026.txt, test_0027.txt, test_0028.txt, test_0029.txt, test_0030.txt, test_0031.txt, test_0032.txt, test_0033.txt, test_0034.txt, test_0035.txt, test_0036.txt, test_0037.txt, test_0038.txt, test_0039.txt, test_0040.txt, test_0041.txt, test_0042.txt, test_0043.txt, test_0044.txt, test_0045.txt, test_0046.txt, test_0047.txt, test_0048.txt, test_0049.txt, test_0050.txt, test_0051.txt, test_0052.txt, test_0053.txt, test_0054.txt, test_0055.txt, test_0056.txt, test_0057.txt, test_0058.txt, test_0059.txt, test_0060.txt, test_0061.txt, test_0062.txt, test_0063.txt, test_0064.txt, test_0065.txt, test_0066.txt, test_0067.txt, test_0068.txt, test_0069.txt, test_0070.txt, test_0071.txt, test_0072.txt, test_0073.txt, test_0074.txt, test_0075.txt, test_0076.txt, test_0077.txt, test_0078.txt, test_0079.txt, test_0080.txt, test_0081.txt, test_0082.txt, test_0083.txt, test_0084.txt, test_0085.txt, test_0086.txt, test_0087.txt, test_0088.txt, test_0089.txt, test_0090.txt, test_0091.txt, test_0092.txt, test_0093.txt, test_0094.txt, test_0095.txt, test_0096.txt, test_0097.txt, test_0098.txt, test_0099.txt, test_0100.txt, test_0101.txt, test_0102.txt, test_0103.txt, test_0104.txt, test_0105.txt, test_0106.txt, test_0107.txt, test_0108.txt, test_0109.txt, test_0110.txt, test_0111.txt, test_0112.txt, test_0113.txt, test_0114.txt, test_0115.txt, test_0116.txt, test_0117.txt, test_0118.txt, test_0119.txt, test_0120.txt, test_0121.txt, test_0122.txt, test_0123.txt, test_0124.txt, test_0125.txt, test_0126.txt, test_0127.txt, test_0128.txt, test_0129.txt, test_0130.txt, test_0131.txt, test_0132.txt, test_0133.txt, test_0134.txt, test_0135.txt, test_0136.txt, test_0137.txt, test_0138.txt, test_0139.txt, test_0140.txt, test_0141.txt, test_0142.txt, test_0143.txt, test_0144.txt, test_0145.txt, test_0146.txt, test_0147.txt, test_0148.txt, test_0149.txt |
Case Name |
Status |
Exec Time |
Memory |
test_0000.txt |
AC |
90 ms |
3652 KiB |
test_0001.txt |
AC |
76 ms |
3572 KiB |
test_0002.txt |
AC |
84 ms |
3568 KiB |
test_0003.txt |
AC |
75 ms |
3540 KiB |
test_0004.txt |
AC |
83 ms |
3512 KiB |
test_0005.txt |
AC |
90 ms |
3732 KiB |
test_0006.txt |
AC |
88 ms |
3652 KiB |
test_0007.txt |
AC |
79 ms |
3660 KiB |
test_0008.txt |
AC |
91 ms |
3576 KiB |
test_0009.txt |
AC |
90 ms |
3524 KiB |
test_0010.txt |
AC |
78 ms |
3600 KiB |
test_0011.txt |
AC |
88 ms |
3612 KiB |
test_0012.txt |
AC |
84 ms |
3608 KiB |
test_0013.txt |
AC |
89 ms |
3540 KiB |
test_0014.txt |
AC |
87 ms |
3648 KiB |
test_0015.txt |
AC |
81 ms |
3540 KiB |
test_0016.txt |
AC |
85 ms |
3656 KiB |
test_0017.txt |
AC |
78 ms |
3600 KiB |
test_0018.txt |
AC |
73 ms |
3588 KiB |
test_0019.txt |
AC |
81 ms |
3560 KiB |
test_0020.txt |
AC |
90 ms |
3544 KiB |
test_0021.txt |
AC |
82 ms |
3548 KiB |
test_0022.txt |
AC |
82 ms |
3576 KiB |
test_0023.txt |
AC |
87 ms |
3552 KiB |
test_0024.txt |
AC |
73 ms |
3592 KiB |
test_0025.txt |
AC |
87 ms |
3520 KiB |
test_0026.txt |
AC |
88 ms |
3652 KiB |
test_0027.txt |
AC |
87 ms |
3548 KiB |
test_0028.txt |
AC |
81 ms |
3616 KiB |
test_0029.txt |
AC |
87 ms |
3456 KiB |
test_0030.txt |
AC |
91 ms |
3476 KiB |
test_0031.txt |
AC |
81 ms |
3516 KiB |
test_0032.txt |
AC |
75 ms |
3612 KiB |
test_0033.txt |
AC |
81 ms |
3612 KiB |
test_0034.txt |
AC |
76 ms |
3656 KiB |
test_0035.txt |
AC |
73 ms |
3588 KiB |
test_0036.txt |
AC |
87 ms |
3588 KiB |
test_0037.txt |
AC |
88 ms |
3512 KiB |
test_0038.txt |
AC |
75 ms |
3520 KiB |
test_0039.txt |
AC |
81 ms |
3452 KiB |
test_0040.txt |
AC |
79 ms |
3732 KiB |
test_0041.txt |
AC |
70 ms |
3544 KiB |
test_0042.txt |
AC |
78 ms |
3604 KiB |
test_0043.txt |
AC |
79 ms |
3540 KiB |
test_0044.txt |
AC |
84 ms |
3544 KiB |
test_0045.txt |
AC |
88 ms |
3604 KiB |
test_0046.txt |
AC |
82 ms |
3604 KiB |
test_0047.txt |
AC |
70 ms |
3540 KiB |
test_0048.txt |
AC |
89 ms |
3600 KiB |
test_0049.txt |
AC |
84 ms |
3520 KiB |
test_0050.txt |
AC |
74 ms |
3572 KiB |
test_0051.txt |
AC |
83 ms |
3548 KiB |
test_0052.txt |
AC |
88 ms |
3656 KiB |
test_0053.txt |
AC |
77 ms |
3600 KiB |
test_0054.txt |
AC |
90 ms |
3584 KiB |
test_0055.txt |
AC |
70 ms |
3596 KiB |
test_0056.txt |
AC |
83 ms |
3452 KiB |
test_0057.txt |
AC |
80 ms |
3452 KiB |
test_0058.txt |
AC |
77 ms |
3660 KiB |
test_0059.txt |
AC |
79 ms |
3604 KiB |
test_0060.txt |
AC |
90 ms |
3604 KiB |
test_0061.txt |
AC |
71 ms |
3544 KiB |
test_0062.txt |
AC |
88 ms |
3652 KiB |
test_0063.txt |
AC |
89 ms |
3604 KiB |
test_0064.txt |
AC |
79 ms |
3512 KiB |
test_0065.txt |
AC |
90 ms |
3460 KiB |
test_0066.txt |
AC |
88 ms |
3544 KiB |
test_0067.txt |
AC |
87 ms |
3504 KiB |
test_0068.txt |
AC |
82 ms |
3580 KiB |
test_0069.txt |
AC |
90 ms |
3548 KiB |
test_0070.txt |
AC |
86 ms |
3524 KiB |
test_0071.txt |
AC |
70 ms |
3552 KiB |
test_0072.txt |
AC |
88 ms |
3596 KiB |
test_0073.txt |
AC |
69 ms |
3596 KiB |
test_0074.txt |
AC |
91 ms |
3536 KiB |
test_0075.txt |
AC |
70 ms |
3588 KiB |
test_0076.txt |
AC |
90 ms |
3456 KiB |
test_0077.txt |
AC |
70 ms |
3548 KiB |
test_0078.txt |
AC |
75 ms |
3552 KiB |
test_0079.txt |
AC |
90 ms |
3544 KiB |
test_0080.txt |
AC |
87 ms |
3460 KiB |
test_0081.txt |
AC |
74 ms |
3596 KiB |
test_0082.txt |
AC |
91 ms |
3452 KiB |
test_0083.txt |
AC |
71 ms |
3732 KiB |
test_0084.txt |
AC |
69 ms |
3596 KiB |
test_0085.txt |
AC |
80 ms |
3528 KiB |
test_0086.txt |
AC |
82 ms |
3552 KiB |
test_0087.txt |
AC |
77 ms |
3540 KiB |
test_0088.txt |
AC |
90 ms |
3604 KiB |
test_0089.txt |
AC |
85 ms |
3604 KiB |
test_0090.txt |
AC |
74 ms |
3600 KiB |
test_0091.txt |
AC |
71 ms |
3548 KiB |
test_0092.txt |
AC |
85 ms |
3588 KiB |
test_0093.txt |
AC |
87 ms |
3516 KiB |
test_0094.txt |
AC |
90 ms |
3548 KiB |
test_0095.txt |
AC |
80 ms |
3576 KiB |
test_0096.txt |
AC |
83 ms |
3572 KiB |
test_0097.txt |
AC |
72 ms |
3660 KiB |
test_0098.txt |
AC |
77 ms |
3588 KiB |
test_0099.txt |
AC |
79 ms |
3652 KiB |
test_0100.txt |
AC |
89 ms |
3648 KiB |
test_0101.txt |
AC |
82 ms |
3516 KiB |
test_0102.txt |
AC |
90 ms |
3524 KiB |
test_0103.txt |
AC |
77 ms |
3528 KiB |
test_0104.txt |
AC |
72 ms |
3620 KiB |
test_0105.txt |
AC |
79 ms |
3548 KiB |
test_0106.txt |
AC |
89 ms |
3544 KiB |
test_0107.txt |
AC |
85 ms |
3600 KiB |
test_0108.txt |
AC |
86 ms |
3544 KiB |
test_0109.txt |
AC |
74 ms |
3740 KiB |
test_0110.txt |
AC |
82 ms |
3552 KiB |
test_0111.txt |
AC |
90 ms |
3528 KiB |
test_0112.txt |
AC |
89 ms |
3460 KiB |
test_0113.txt |
AC |
86 ms |
3732 KiB |
test_0114.txt |
AC |
81 ms |
3604 KiB |
test_0115.txt |
AC |
80 ms |
3516 KiB |
test_0116.txt |
AC |
90 ms |
3660 KiB |
test_0117.txt |
AC |
83 ms |
3600 KiB |
test_0118.txt |
AC |
85 ms |
3612 KiB |
test_0119.txt |
AC |
81 ms |
3604 KiB |
test_0120.txt |
AC |
69 ms |
3540 KiB |
test_0121.txt |
AC |
88 ms |
3736 KiB |
test_0122.txt |
AC |
79 ms |
3592 KiB |
test_0123.txt |
AC |
74 ms |
3664 KiB |
test_0124.txt |
AC |
72 ms |
3572 KiB |
test_0125.txt |
AC |
79 ms |
3648 KiB |
test_0126.txt |
AC |
80 ms |
3568 KiB |
test_0127.txt |
AC |
79 ms |
3544 KiB |
test_0128.txt |
AC |
80 ms |
3600 KiB |
test_0129.txt |
AC |
86 ms |
3700 KiB |
test_0130.txt |
AC |
79 ms |
3568 KiB |
test_0131.txt |
AC |
75 ms |
3456 KiB |
test_0132.txt |
AC |
73 ms |
3656 KiB |
test_0133.txt |
AC |
70 ms |
3572 KiB |
test_0134.txt |
AC |
74 ms |
3552 KiB |
test_0135.txt |
AC |
69 ms |
3620 KiB |
test_0136.txt |
AC |
82 ms |
3700 KiB |
test_0137.txt |
AC |
81 ms |
3532 KiB |
test_0138.txt |
AC |
75 ms |
3604 KiB |
test_0139.txt |
AC |
92 ms |
3608 KiB |
test_0140.txt |
AC |
80 ms |
3604 KiB |
test_0141.txt |
AC |
72 ms |
3588 KiB |
test_0142.txt |
AC |
89 ms |
3608 KiB |
test_0143.txt |
AC |
84 ms |
3728 KiB |
test_0144.txt |
AC |
86 ms |
3592 KiB |
test_0145.txt |
AC |
91 ms |
3728 KiB |
test_0146.txt |
AC |
85 ms |
3648 KiB |
test_0147.txt |
AC |
74 ms |
3572 KiB |
test_0148.txt |
AC |
79 ms |
3540 KiB |
test_0149.txt |
AC |
82 ms |
3616 KiB |