Submission #3859748


Source Code Expand

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

namespace io {
    // TYPE ID (StackOverflow)
    
    template<class T> struct like_array : is_array<T>{};
    template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
    template<class T> struct like_array<vector<T>> : true_type{};
    template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }

    // I/O 
    
    void setIn(string s) { freopen(s.c_str(),"r",stdin); }
    void setOut(string s) { freopen(s.c_str(),"w",stdout); }
    void setIO(string s = "") {
        ios_base::sync_with_stdio(0); cin.tie(0);
        if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
    }
    
    // INPUT 
    
    template<class T> void re(T& x) { cin >> x; }
    template<class Arg, class... Args> void re(Arg& first, Args&... rest);
    void re(double& x) { string t; re(t); x = stod(t); }
    void re(ld& x) { string t; re(t); x = stold(t); }
    
    template<class T> void re(complex<T>& x);
    template<class T1, class T2> void re(pair<T1,T2>& p);
    template<class T> void re(vector<T>& a);
    template<class T, size_t SZ> void re(array<T,SZ>& a);
    
    template<class Arg, class... Args> void re(Arg& first, Args&... rest) { re(first); re(rest...); }
    template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
    template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
    template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
    template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
    
    // OUTPUT 
    
    template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
        os << '{' << a.f << ", " << a.s << '}'; return os;
    }
    template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
        os << '{';
        F0R(i,SZ) {
            if (i) {
                os << ", ";
                if (is_like_array(a[i])) cout << "\n";
            }
            os << a[i];
        }
        os << '}';
        return os;
    }
    template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
        return printArray(os,a,SZ);
    }
    template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
        return printArray(os,a,sz(a));
    }
    template<class T> ostream& operator<<(ostream& os, const set<T>& a) {
        os << vector<T>(all(a)); return os;
    }
    template<class T1, class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {
        os << vector<pair<T1,T2>>(all(a)); return os;
    }
    
    template<class T> void pr(const T& x) { cout << x << '\n'; }
    template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) { 
        cout << first << ' '; pr(rest...); 
    }
}

using namespace io;

ll K;
vl v[8];
vi indices; 
int N = 500;
string str = "FESTIVAL", res;

int main() {
    // you should actually read the stuff at the bottom
    setIO(); re(K);
    F0R(i,N) {
        v[0].pb(1);
        res += str[0];
        indices.pb(i);
    }
    FOR(j,1,8) {
        ll sum = 0; int ind = 0;
        vi tmp;
        F0R(i,N) {
            ll lst = sum;
            while (ind == 0 || (ind < N && 2*lst > sum)) {
                sum += v[j-1][ind++];   
            }
            tmp.pb(ind-1);
            v[j].pb(sum);
        }
        if (j < 7) {
            F0Rd(i,N) res.insert(res.begin()+indices[tmp[i]]+1,str[j]);
            indices.clear();
            F0R(i,sz(res)) if (res[i] == str[j]) indices.pb(i);
        } else {
            int ind = sz(v[j])-1;
            while (K) {
                while (v[j][ind] > K) ind --;
               //  pr(ind);
                res.insert(res.begin()+indices[tmp[ind]]+1,str[j]);
                K -= v[j][ind];
            }
            pr(res);
        }
    }
    
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do smth instead of nothing and stay organized
*/

Submission Info

Submission Time
Task G - FESTIVAL
User Benq
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 5543 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘void io::setIn(std::string)’:
./Main.cpp:67:56: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     void setIn(string s) { freopen(s.c_str(),"r",stdin); }
                                                        ^
./Main.cpp: In function ‘void io::setOut(std::string)’:
./Main.cpp:68:58: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
     void setOut(string s) { freopen(s.c_str(),"w",stdout); }
                                                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 2
AC × 56
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 256 KB
001.txt AC 1 ms 256 KB
002.txt AC 1 ms 256 KB
003.txt AC 1 ms 256 KB
004.txt AC 1 ms 256 KB
005.txt AC 2 ms 256 KB
006.txt AC 1 ms 256 KB
007.txt AC 1 ms 256 KB
008.txt AC 1 ms 256 KB
009.txt AC 1 ms 256 KB
010.txt AC 1 ms 256 KB
011.txt AC 1 ms 256 KB
012.txt AC 1 ms 256 KB
013.txt AC 1 ms 256 KB
014.txt AC 2 ms 256 KB
015.txt AC 1 ms 256 KB
016.txt AC 1 ms 256 KB
017.txt AC 1 ms 256 KB
018.txt AC 1 ms 256 KB
019.txt AC 2 ms 256 KB
020.txt AC 1 ms 256 KB
021.txt AC 1 ms 256 KB
022.txt AC 1 ms 256 KB
023.txt AC 1 ms 256 KB
024.txt AC 2 ms 256 KB
025.txt AC 1 ms 256 KB
026.txt AC 1 ms 256 KB
027.txt AC 1 ms 256 KB
028.txt AC 1 ms 256 KB
029.txt AC 1 ms 256 KB
030.txt AC 1 ms 256 KB
031.txt AC 1 ms 256 KB
032.txt AC 1 ms 256 KB
033.txt AC 1 ms 256 KB
034.txt AC 1 ms 256 KB
035.txt AC 2 ms 256 KB
036.txt AC 2 ms 256 KB
037.txt AC 2 ms 256 KB
038.txt AC 2 ms 256 KB
039.txt AC 2 ms 256 KB
040.txt AC 2 ms 256 KB
041.txt AC 2 ms 256 KB
042.txt AC 1 ms 256 KB
043.txt AC 2 ms 256 KB
044.txt AC 1 ms 256 KB
045.txt AC 1 ms 256 KB
046.txt AC 2 ms 256 KB
047.txt AC 1 ms 256 KB
048.txt AC 1 ms 256 KB
049.txt AC 1 ms 256 KB
050.txt AC 1 ms 256 KB
051.txt AC 1 ms 256 KB
052.txt AC 2 ms 256 KB
053.txt AC 2 ms 256 KB
example0.txt AC 2 ms 256 KB
example1.txt AC 2 ms 256 KB