답안 #1082358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082358 2024-08-31T08:12:32 Z tte0 Binaria (CCO23_day1problem1) C++17
18 / 25
1000 ms 17848 KB
/*
Author: Teoman Ata Korkmaz
*/
#pragma GCC optimize("O3,fast-math,unroll-loops,no-stack-protector")
#include <bits/stdc++.h> 
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define int ll
#define ff first
#define ss second
#define endl '\n'
#define spc ' '
#define pb push_back
#define e2(x) (1LL<<(x))
#define lg(x) (__lg(x))
#define gcd(x,y) __gcd(x,y)
#define lcm(x,y) ((x/gcd(x,y))*y)
#define smrt(i) (double(sqrt(8*(i)+1)-1)/2)
#define ssum(x) ((x)*((x)+1)/2)
#define isint(x) (ceil((x))==floor((x)))
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define cendl cout<<endl
#define mset(x,y) memset(x,y,sizeof(x))
#define popcnt(x) __builtin_popcountll(x)
#define clz(x) __builtin_clz(x)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define clock() uint64_t(chrono::high_resolution_clock::now().time_since_epoch().count())
#define compress(x) sort(all(x));x.resize(unique(all(x))-x.begin())
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);cout<<fixed<<setprecision(0);cerr<<fixed<<setprecision(0)
#define fileio freopen("out.txt","w",stdout);freopen("in.txt","r",stdin)
#define usacoio(s) freopen((s + str(".in")).c_str(), "r", stdin);freopen((s + str(".out")).c_str(), "w", stdout)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
//using namespace __gnu_pbds;
typedef int_fast32_t i32;
typedef int_fast64_t ll;
typedef long double ldouble;
typedef string str;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair<ii,ii> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pair<char,int>> vci;
typedef vector<str> vstr;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<str,int> msi;
typedef map<int,vi> miv;
typedef unordered_map<int,int> umii;
typedef unordered_map<char,int> umci;
typedef unordered_map<str,int> umsi;
typedef unordered_map<int,vi> umiv;
typedef set<int> sti;
typedef set<char> stc;
typedef set<str> sts;
typedef multiset<int> msti;
typedef multiset<char> mstc;
typedef multiset<str> msts;
inline int segsum(int start,int end,int step){
    if(end<start)return 0;
    return (((end-start)/step+1)*(start+end))>>1;
}
inline int fp(int b,int p,int mod=1e9+7){
    int ans=1;
    while(p){
        if(p&1)ans=(ans*b)%mod;
        p>>=1;
        b=(b*b)%mod;
    }
    return ans;
}
template<typename InputIterator,typename T = int>
T accumulate(InputIterator first,InputIterator last,T init = T{}) {
    for (; first != last; ++first) {
        init += *first;
    }
    return init;
}
template<typename T,typename T2>inline pair<T,T2> operator+(const pair<T,T2>&a,const pair<T,T2>& b){return {a.ff+b.ff,a.ss+b.ss};}
template<typename T,typename T2>inline pair<T,T2> operator-(const pair<T,T2>&a,const pair<T,T2>& b){return {a.ff-b.ff,a.ss-b.ss};}
template<typename T,typename T2>inline pair<T,T2> operator*(const pair<T,T2>&a,const pair<T,T2>& b){return {a.ff*b.ff,a.ss*b.ss};}
template<typename T,typename T2>inline pair<T,T2> operator/(const pair<T,T2>&a,const pair<T,T2>& b){return {a.ff/b.ff,a.ss/b.ss};}
template<typename T> inline void maxs(T& x,const T& y){return void(x=max(x,y));}
template<typename T> inline void mins(T& x,const T& y){return void(x=min(x,y));}
template<typename T> inline void gcds(T& x,const T& y){return void(x=gcd(x,y));}
template<typename T> inline void lcms(T& x,const T& y){return void(x=lcm(x,y));}
template<typename T,typename T2>inline ostream& operator<<(ostream& os, const pair<T,T2>& p){
    os<<"["<<p.ff<<","<<p.ss<<"]";
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const vector<T>& a) {
    for(const T& _:a)os<<_<<' ';
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const vector<vector<T>>& a) {
    for(const vector<T>& _:a)os<<_<<endl;
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const set<T>& a) {
    for(const T& _:a)os<<_<<' ';
    return os;
}
template<typename T,typename T2>inline ostream& operator<<(ostream& os,const map<T,T2>& a) {
    for(const auto& _:a)os<<_<<' ';
    return os;
}
template<typename T,typename T2>inline ostream& operator<<(ostream& os,const unordered_map<T,T2>& a) {
    for(const auto& _:a)os<<_<<' ';
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const queue<T>& b) {
    queue<T> a=b;
    while(a.size()){
        os<<a.front()<<" ";
        a.pop();
    }
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const stack<T>& b) {
    stack<T> a=b;
    while(a.size()){
        os<<a.top()<<" ";
        a.pop();
    }
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const priority_queue<T>& b) {
    priority_queue<T> a=b;
    while(a.size()){
        os<<a.top()<<" ";
        a.pop();
    }
    return os;
}
template<typename T>inline ostream& operator<<(ostream& os,const priority_queue<T,vector<T>,greater<T>>& b) {
    priority_queue<T,vector<T>,greater<T>> a=b;
    while(a.size()){
        os<<a.top()<<" ";
        a.pop();
    }
    return os;
}
template<typename T,typename T2>inline istream& operator>>(istream& is,pair<T,T2>& p){
    is>>(p.ff)>>(p.ss);
    return is;
}
template<typename T>inline istream& operator>>(istream& is,vector<T>& a) {
    for(T& _:a)is>>_;
    return is;
}
inline void print(){cout<<endl;}
template<typename... Args>
inline void print(const Args&... args){
    ((cout<<args<<' '),...)<<endl;
}
inline void input(){}
template<typename... Args>
inline void input(Args&... args){
    (cin>>...>>args);
}
#ifdef ONLINE_JUDGE
template<typename... Args>
inline void debug(const Args&... args){
    return void("59");
}
#else
inline void debug(){cerr<<endl;}
template<typename... Args>
inline void debug(const Args&... args){
    ((cerr<<args<<' '),...)<<endl;
}
#endif
inline void yn(bool b){
    if(b)yes;
    else no;
}
#define ASSERT(condition, message)\
if(condition){\
    cerr<<"Assertion failed: "<<message<<" at "<<__FILE__<<":"<<to_string(__LINE__)<<endl;\
    abort();\
}
///////////////////////////////////////////////////////////////////
constexpr int N=2e5+5;
constexpr int A=1e9+5;
constexpr int MOD=1e6+3;
constexpr i32 INF=INT32_MAX;
constexpr ll  INFL=INT64_MAX;
constexpr int BLOCK=320;
constexpr ldouble EPS=1e-9;
constexpr int MAXQUERY=100;
constexpr int dx[4]={-1,0,1,0};
constexpr int dy[4]={0,1,0,-1};
mt19937 mt(clock());
///////////////////////////////////////////////////////////////////
int n,m,k,t,q,a,b,x,y,w;
vi v,ans,adj[N];

inline int ncr(int n,int r){
    debug("ncr:",n,r);
    ASSERT(n<r,"n<r");
    ASSERT(n<0,"n<0");
    ASSERT(r<0,"r<0");
    int ans=1,b=1;
    for(int i=n;i>n-r;i--)ans=(ans*i)%MOD;
    for(int i=1;i<=r;i++) b=(b*i)%MOD;
    ans=(ans*fp(b,MOD-2,MOD))%MOD;
    return ans;
}

inline void solve(void){
    input(n,k);
    v.resize(n-k+1);
    ans.assign(k,-1);
    input(v);
    for(int i=0;i<int(v.size())-1;i++){
        if(ans[i%k]!=-1)continue;
        if(v[i]-v[i+1]==-1){
            ans[i%k]=0;
        }
        else if(v[i]-v[i+1]==1){
            ans[i%k]=1;
        }
    }

    debug("ans:",ans);

    int x=v[0],cnt=0;
    for(int i=0;i<k;i++){
        if(ans[i]==1)x--;
        if(ans[i]==-1)cnt++;
    }


    print(ncr(cnt,x));
}

signed main(void){
    int start=clock();
    fastio;
    //usacoio("59");
    int _testcase=1;
    //cin>>_testcase;
    while(_testcase--)solve();
    debug("Time elapsed:",(clock()-start)/uint64_t(1e6),"ms");
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 4 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5160 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 4 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5160 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 5 ms 5164 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 4 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5160 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 5 ms 5164 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 5020 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 3 ms 4952 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 4 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5160 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 5 ms 5164 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 5020 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 3 ms 4952 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 41 ms 14932 KB Output is correct
36 Correct 50 ms 15420 KB Output is correct
37 Correct 47 ms 15700 KB Output is correct
38 Correct 45 ms 15928 KB Output is correct
39 Correct 41 ms 14932 KB Output is correct
40 Correct 46 ms 15700 KB Output is correct
41 Correct 46 ms 15696 KB Output is correct
42 Correct 43 ms 14932 KB Output is correct
43 Correct 41 ms 14904 KB Output is correct
44 Correct 42 ms 14888 KB Output is correct
45 Correct 41 ms 14936 KB Output is correct
46 Correct 44 ms 14888 KB Output is correct
47 Correct 42 ms 14932 KB Output is correct
48 Correct 45 ms 15796 KB Output is correct
49 Correct 45 ms 15700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 4 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5160 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 5 ms 5164 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 5020 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 3 ms 4952 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 41 ms 14932 KB Output is correct
36 Correct 50 ms 15420 KB Output is correct
37 Correct 47 ms 15700 KB Output is correct
38 Correct 45 ms 15928 KB Output is correct
39 Correct 41 ms 14932 KB Output is correct
40 Correct 46 ms 15700 KB Output is correct
41 Correct 46 ms 15696 KB Output is correct
42 Correct 43 ms 14932 KB Output is correct
43 Correct 41 ms 14904 KB Output is correct
44 Correct 42 ms 14888 KB Output is correct
45 Correct 41 ms 14936 KB Output is correct
46 Correct 44 ms 14888 KB Output is correct
47 Correct 42 ms 14932 KB Output is correct
48 Correct 45 ms 15796 KB Output is correct
49 Correct 45 ms 15700 KB Output is correct
50 Correct 60 ms 17848 KB Output is correct
51 Correct 61 ms 17744 KB Output is correct
52 Correct 61 ms 17720 KB Output is correct
53 Correct 71 ms 17748 KB Output is correct
54 Correct 66 ms 17716 KB Output is correct
55 Correct 61 ms 17848 KB Output is correct
56 Correct 60 ms 17704 KB Output is correct
57 Correct 56 ms 16808 KB Output is correct
58 Correct 62 ms 17748 KB Output is correct
59 Correct 68 ms 17724 KB Output is correct
60 Correct 57 ms 16692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 4 ms 4956 KB Output is correct
3 Correct 3 ms 4956 KB Output is correct
4 Correct 2 ms 5160 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 5160 KB Output is correct
12 Correct 3 ms 5212 KB Output is correct
13 Correct 3 ms 4952 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 5 ms 5164 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 2 ms 5160 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4952 KB Output is correct
22 Correct 3 ms 4952 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 5020 KB Output is correct
25 Correct 3 ms 4956 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 3 ms 4956 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 3 ms 4956 KB Output is correct
33 Correct 3 ms 4952 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 41 ms 14932 KB Output is correct
36 Correct 50 ms 15420 KB Output is correct
37 Correct 47 ms 15700 KB Output is correct
38 Correct 45 ms 15928 KB Output is correct
39 Correct 41 ms 14932 KB Output is correct
40 Correct 46 ms 15700 KB Output is correct
41 Correct 46 ms 15696 KB Output is correct
42 Correct 43 ms 14932 KB Output is correct
43 Correct 41 ms 14904 KB Output is correct
44 Correct 42 ms 14888 KB Output is correct
45 Correct 41 ms 14936 KB Output is correct
46 Correct 44 ms 14888 KB Output is correct
47 Correct 42 ms 14932 KB Output is correct
48 Correct 45 ms 15796 KB Output is correct
49 Correct 45 ms 15700 KB Output is correct
50 Correct 60 ms 17848 KB Output is correct
51 Correct 61 ms 17744 KB Output is correct
52 Correct 61 ms 17720 KB Output is correct
53 Correct 71 ms 17748 KB Output is correct
54 Correct 66 ms 17716 KB Output is correct
55 Correct 61 ms 17848 KB Output is correct
56 Correct 60 ms 17704 KB Output is correct
57 Correct 56 ms 16808 KB Output is correct
58 Correct 62 ms 17748 KB Output is correct
59 Correct 68 ms 17724 KB Output is correct
60 Correct 57 ms 16692 KB Output is correct
61 Execution timed out 1012 ms 14444 KB Time limit exceeded
62 Halted 0 ms 0 KB -