This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#include "grader.h"
//#include "grader.cpp"
#define f first
#define s second
#define pb push_back
#define vec vector
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef pair<int,int> pii;
typedef long double ld;
auto rng=bind(uniform_int_distribution<long long>(1,1e18),mt19937(time(0)));
typedef long long ll;
template <class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template <class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
const ll inf=1e18+100;
//const int N=49;
ll get(vec<string> s,bool dbg=0){
int n=sz(s),m=sz(s[0]);
vec<vec<vec<ll>>>dp(n,vec<vec<ll>>(m,vec<ll>(2,0)));
if(s[0][0]=='r' || s[0][0]=='X')dp[0][0][0]=1;
if(s[0][0]=='d' || s[0][0]=='X')dp[0][0][1]=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(i==0 && j==0) continue;
// if(dbg && j==2){
// debug()<<
// }
dp[i][j][0]=(i&&s[i-1][j]!='r'?dp[i-1][j][0]:0);
dp[i][j][1]=(j&&s[i][j-1]!='d'?dp[i][j-1][1]:0);
ll sm=dp[i][j][0]+dp[i][j][1];
if(s[i][j]=='X'){
dp[i][j][0]=sm;
dp[i][j][1]=sm;
}
else if(s[i][j]=='d') dp[i][j][0]=sm;
else if(s[i][j]=='r') dp[i][j][1]=sm;
umin(dp[i][j][0],inf);umin(dp[i][j][1],inf);
}
}
return dp[n-1][m-1][0]+dp[n-1][m-1][1];
}
signed main(){
///let me bruteforce
ll k;
cin>>k;
int n=(k<=19?5:49);
vec<string>s(n,string(n,'.'));
for(int i=0;i<n;i++) s[0][i]=s[n-1][i]='r';
for(int i=0;i<n;i++) s[i][0]=s[i][n-1]='d';
for(int i=1;i<n-2;i+=2){
s[i][i]=s[i+1][i+1]=s[i][i+1]=s[i+1][i]='X';
s[i+2][i]=s[i+2][i+1]='r';
s[i][i+2]=s[i+1][i+2]='d';
}
s[0][0]='X';s[n-1][n-1]='.';s[n-1][0]='r';
ll nk=k;
ll last=get(s);
vec<array<ll,3>>go;
for(int i=1;i<n-1;i++){
s[0][i]='X';
ll me=get(s,1);
go.pb({me-last,0,i});
go.pb({me-last,i,0});
s[0][i]='r';
}
cout<<n<<' '<<n<<endl;
sort(rall(go));
assert(last==2);
k-=2;
for(auto &z : go){
if(k>=z[0]){
s[z[1]][z[2]]='X';
k-=z[0];
}
}
// debug()<<imie(k);
assert(k==0);
assert(get(s)==nk);
for(int i=0;i<n;i++) cout<<s[i]<<endl;
// debug()<<imie(s);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |