GithubHelp home page GithubHelp logo

nzpc-2018's People

Contributors

robert-king avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

solomonli pcrane

nzpc-2018's Issues

Here is my solution for O

#include "bits/stdc++.h"
//#include "ext/pb_ds/tree_policy.hpp"
//#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define EX0 exit(0);

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ll inf = 1e9+7;
const ld eps = 1e-9;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a) {
    if(a<0)return -1;
    if(a>0)return 1;
    return 0;
}

template<typename T,typename S>inline bool upmin(T&a,const S&b){return a>b?a=b,1:0;}
template<typename T,typename S>inline bool upmax(T&a,const S&b){return a<b?a=b,1:0;}

template<typename T> inline void in(T &x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch))  {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    x *= f;
}

ll twop(int x) {
    return 1LL<<x;
}

template<typename A,typename B > inline void in(A&x,B&y) {
    in(x);
    in(y);
}
template<typename A,typename B,typename C>inline void in(A&x,B&y,C&z) {
    in(x);
    in(y);
    in(z);
}
template<typename A,typename B,typename C,typename D> inline void in(A&x,B&y,C&z,D&d) {
    in(x);
    in(y);
    in(z);
    in(d);
}


const ll inv = 166666668;
// m must be positive
template<typename T>
static T MOD(T a, T m)
{
    a %= m;
    if (a < 0)
        a += m;
    return a;
}

// a must be relatively prime to m
template<typename T>
static T inverse(T a, T m)
{
    a = MOD(a, m);
    if (a <= 1)
        return a;
    return MOD((1 - inverse(m, a) * m) / a, m);
}

vector<VLL>equ;
set<int>reachable;

namespace SOLVE {
    int n;
    vector<int>v(1000);

    void bfs(){
        int cur = 1;
        queue<int>q;
        q.push(cur);
        while (sz(q)) {
            int f = q.front();q.pop();
            reachable.insert(f);
            REP(i,1,7){
                if(f+i <= n){
                    if(v[f+i] == 0 && reachable.count(f+i)==0)q.push(f+i);
                    else{if(reachable.count(v[f+i])==0) q.push(v[f+i]);}
                }
            }
        }
        reachable.insert(n);
    }
    void main(){
        cin>>n;
        REP(i,1,n+1)in(v[i]);
        bfs();
        int row = 0;
//        for(auto i:reachable)dbg(i);
        REP(i,1,n+1){
            if(v[i] == 0 && reachable.count(i)){
                VLL tmp(n+1,0);
                tmp[i-1] = 1;
                tmp[n] = 1;
                REP(j,1,7){
                    if(i+j < n){
                        if(v[i+j] == 0){
                            (tmp[i+j-1] += mod-inv)%=mod;
                        }else{
                            (tmp[v[i+j]-1] += mod-inv)%=mod;
                        }
                    }
                }
                equ.PB(tmp);
            }
        }
        equ.back().back() = 0;
//        REP(i,0,sz(equ)){
//            REP(j,0,n+1){
//                cout<<equ[i][j]<<" ";
//            }
//            cout<<endl;
//        }
        REP(i,0,sz(equ))swap(equ[i][0],equ[i][n-1]);
        int curRow = 0;
        REP(i,0,n){
            bool exist = 0;
            REP(j,curRow,sz(equ)){
                if(equ[j][i]){
                    swap(equ[j], equ[curRow]);
                    exist = 1;
                    break;
                }
            }
            if(exist){
//                dbg(i);

                REP(c,i+1,n+1){
                    equ[curRow][c] *= inverse(equ[curRow][i], mod);
                    (equ[curRow][c])%=mod;
                }
                equ[curRow][i] = 1;
                REP(r,curRow+1,sz(equ)){
                    
                    REP(c,i+1,n+1){
                        equ[r][c] -= equ[curRow][c] * equ[r][i];
                        equ[r][c] = ((equ[r][c])%mod+mod)%mod;
                    }
                    equ[r][i] = 0;
                }
                curRow++;
            }
        }
//        REP(i,0,sz(equ)){
//            REP(j,0,n+1){
//                cout<<equ[i][j]<<" ";
//            }
//            cout<<endl;
//        }
        cout<<equ.back()[n]<<endl;
    }
}


int main() {
    
    
    
    
    
    
    SOLVE::main();
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

BTW, could you plz briefly explain the idea for K? I tried to go backwards but it ended up with TLE. Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.