#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()
#define m_p make_pair
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;
typedef long long ll;
auto rng=bind(uniform_int_distribution<ll>(1,1e18),mt19937(time(0)));
const ll inf=1e18;
template <class T> bool umin(T &a, T b){return (a>b?a=b,1:0);}
template <class T> bool umax(T &a, T b){return (a<b?a=b,1:0);}
//const int N=49;<
vec<vec<vec<ll>>>dp;
ll get(vec<string> s,bool dbg=0){
int n=sz(s),m=sz(s[0]);
vec<vec<vec<ll>>>ndp(n,vec<vec<ll>>(m,vec<ll>(2,0)));
dp=ndp;
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);
// if(dbg)debug()<<imie(i)imie(j)imie(dp[i][j][0])imie(dp[i][j][1]);
}
}
// if(dbg)
return dp[n-1][m-1][0]+dp[n-1][m-1][1];
}
signed main(){
///let me bruteforce
int n=33,m=33;
ll k=19;
cin>>k;
// if(k<=19){
// n=5;m=5;
// vec<string>s(n,string(m,'.'));
// for(int i=0;i<m;i++){
// s[n-1][i]='r';
// }
// for(int i=0;i<n;i++) s[i][m-1]='d';
// s[n-1][m-1]='.';
// cout<<n<<' '<<m<<endl;
// for(int mask=0;mask<(1<<((n-1)*(m-1)));mask++){
// vec<string>me=s;
// for(int i=0;i<(n-1)*(m-1);i++){
// if((1<<i)&mask){
// me[i/(m-1)][i%(m-1)]='X';
// }
// }
// ll how=get(me);
//// cout<<how<<endl;
//// if(mask==1){
////// cout<<get(me,1);
//// }
// if(how==k && me[0][0]!='.'){
// for(int i=0;i<n;i++) cout<<me[i]<<endl;
//// cout<<get(me,1);
// return 0;
// }
//// debug()<<imie(how);
//// for(int i=0;i<4;i++) debug()<<imie(me[i]);
//// debug()<<imie(me)imie(how);
// }
// }
n=49;m=49;
if(k<=19) n=5,m=5;
cout<<n<<' '<<m<<endl;
vec<string>s(n,string(m,'.'));
for(int i=0;i<m;i++){
s[n-1][i]='r';
}
for(int i=0;i<n;i++) s[i][m-1]='d';
s[n-1][m-1]='.';
auto check=[&](int x,int y){
vec<string>tb(x,string(y,'X'));
return get(tb);
};
int rem=m;
int st=0;
s[0][0]='X';
// k-=2;
// while(k!=0){
get(s);
ll mx=0;
pii w={-1,-1};
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
// ll how=dp[i][]
if(i==n-1 && j==m-1) continue;
if(s[i][j]=='.'){
s[i][j]='X';
ll how=get(s);
if(how<=k){
continue;
}
s[i][j]='.';
// debug()<<imie(how);
}
}
}
// s[w.f][w.s]='X';
// if(1){
// cout<<"DEBUG "<<k<<' '<<get(s)<<endl;
// for(int i=0;i<n;i++){
// cout<<s[i]<<endl;
// }
// if(mx==0) break;
//// return 0;
// }
// k-=mx;s[w.f][w.s]='X';
// }
// cout<<get(s)<<endl;
assert(k==get(s));
// cout<<"GOOD"<<endl;
cout<<get(s)<<endl;
for(int i=0;i<n;i++) cout<<s[i]<<endl;
return 0;
}
Compilation message
costinland.cpp: In function 'int main()':
costinland.cpp:127:10: warning: variable 'check' set but not used [-Wunused-but-set-variable]
127 | auto check=[&](int x,int y){
| ^~~~~
costinland.cpp:131:9: warning: unused variable 'rem' [-Wunused-variable]
131 | int rem=m;
| ^~~
costinland.cpp:132:9: warning: unused variable 'st' [-Wunused-variable]
132 | int st=0;
| ^~
costinland.cpp:137:12: warning: unused variable 'mx' [-Wunused-variable]
137 | ll mx=0;
| ^~
costinland.cpp:138:13: warning: variable 'w' set but not used [-Wunused-but-set-variable]
138 | pii w={-1,-1};
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Token "3" doesn't correspond to pattern "[Xrd\.]{5}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
385 ms |
948 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |