답안 #398165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398165 2021-05-03T20:17:29 Z MarcoMeijer Costinland (info1cup19_costinland) C++14
59.8661 / 100
19 ms 31692 KB
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<ll, ll, ll> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e18
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
// input
template<class T> void IN(T& x) {cin >> x;}
template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); }
 
// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }
 
// dp
template<class T> bool ckmin(T&a, T&b) { bool bl = a > b; a = min(a,b); return bl;}
template<class T> bool ckmax(T&a, T&b) { bool bl = a < b; a = max(a,b); return bl;}
 
void program();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    program();
}
 
 
//===================//
//   begin program   //
//===================//
 
const int MX = 2000;
const int N = (1<<20);

ll k, n;
ll dp[MX][MX];
ll dpr[MX][MX], dpd[MX][MX];
ll cnt[MX][MX];
string ans[MX];

ll calculate() {
    memset(dpr,0,sizeof(dpr));
    memset(dpd,0,sizeof(dpd));
    dpr[0][0] = 1;
    RE(i,n) RE(j,n) {
        ll tot = dpr[i][j] + dpd[i][j];
        if(ans[i][j] == 'r') dpr[i  ][j+1] += tot;
        if(ans[i][j] == 'd') dpd[i+1][j  ] += tot;
        if(ans[i][j] == 'X') dpd[i+1][j  ] += tot, dpr[i][j+1] += tot;
        if(ans[i][j] == '.') dpd[i+1][j] += dpd[i][j], dpr[i][j+1] += dpr[i][j];
    }
    return dpr[n-1][n-1] + dpd[n-1][n-1];
}

void program() {
    IN(k);
    n = k <= 19 ? 7 : 63;

    RE(i,n) ans[i] = string(n,'.');
    RE(i,n-1) ans[n-1][i] = 'r';
    RE(i,n-1) ans[i][n-1] = 'd';
    RE(i,n-1) ans[i+1][i] = 'r';
    RE(i,n-1) ans[i][i+1] = 'd';
    ans[0][0] = 'd';
    ans[1][0] = 'd';
    RE(i,n-3) ans[2+i][i] = 'd';

    ll curTot = 1;
    ll m = n-4; // "pyramid" size

    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    RE(i,m) {
        RE(j,i+1) {
            if(dp[i][j] && curTot + dp[i][j] <= k) {
                curTot += dp[i][j];
                ans[3+i][j] = 'X';
                dp[i+1][j] += dp[i][j];
                if(j == i) dp[i+1][j+1] += dp[i][j];
                else       dp[i  ][j+1] += dp[i][j];
            } else {
                dp[i+1][j] += dp[i][j];
                ans[3+i][j] = 'd';
            }
        }
    }

    ll remaining = k - curTot;
    if(remaining) {
        ans[1][0] = 'X';
        ll highestBit = 0;
        RE(i,62) if(remaining&(1ll<<i)) highestBit = i;
        RE(i,highestBit) ans[i][i] = 'X';
        remaining -= (1ll<<highestBit);
        RE(i,62) if(remaining&(1ll<<i)) {
            remaining -= (1ll<<i);
            ans[i][i+1] = 'X';
        }
    }

    OUTLS(n,n);
    RE(i,n) OUTL(ans[i]);
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 17 ms 31692 KB Partially Correct! Your size: 7
2 Partially correct 19 ms 31680 KB Partially Correct! Your size: 7
3 Partially correct 17 ms 31656 KB Partially Correct! Your size: 7
4 Partially correct 17 ms 31692 KB Partially Correct! Your size: 7
5 Partially correct 17 ms 31592 KB Partially Correct! Your size: 7
6 Partially correct 17 ms 31648 KB Partially Correct! Your size: 7
7 Partially correct 17 ms 31692 KB Partially Correct! Your size: 7
8 Partially correct 17 ms 31692 KB Partially Correct! Your size: 7
9 Partially correct 17 ms 31676 KB Partially Correct! Your size: 7
# 결과 실행 시간 메모리 Grader output
1 Partially correct 18 ms 31684 KB Partially Correct! Your size: 63
2 Partially correct 17 ms 31692 KB Partially Correct! Your size: 63
3 Partially correct 17 ms 31600 KB Partially Correct! Your size: 63
4 Partially correct 17 ms 31668 KB Partially Correct! Your size: 63
5 Partially correct 17 ms 31692 KB Partially Correct! Your size: 63
6 Partially correct 17 ms 31692 KB Partially Correct! Your size: 63
7 Partially correct 16 ms 31656 KB Partially Correct! Your size: 63
8 Partially correct 19 ms 31596 KB Partially Correct! Your size: 63