Submission #3551197


Source Code Expand

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
const ll p = 1000000007;
ll dx[4] = {-7,-1,1,7};
ll N,M,Q;
static ll a[100002] = {};
static bool grid[700003] = {};
static bool visited[1500003] = {};
static bool visited2[1500003] = {};

void dfs0(ll pos){
    if (visited[pos]) return;
    visited[pos] = true;

    REP(k,4){
        ll next = pos + dx[k];
        if (next >= 7*N) continue;
        if (next < 0) continue;
        if ((k==1) and (pos % 7 == 0)) continue;
        if ((k==2) and (pos % 7 == 6)) continue;
        if (grid[next]) continue;
        if (visited[next]) continue;
        dfs0(next);
    }

    return;
}

void dfs1(ll pos){
    if (visited[pos]) return;
    visited[pos] = true;

    REP(k,4){
        ll next = pos + dx[k];
        if (next >= M) continue;
        if (next < 0) continue;
        if ((k==1) and (pos % 7 == 0)) continue;
        if ((k==2) and (pos % 7 == 6)) continue;
        if (grid[next]) continue;
        if (visited[next]) continue;
        dfs1(next);
    }

    return;
}

void dfs2(ll pos){
    if (visited2[pos]) return;
    visited2[pos] = true;

    REP(k,4){
        ll next = pos + dx[k];
        if (next >= 2*M) continue;
        if (next < 0) continue;
        if ((k==1) and (pos % 7 == 0)) continue;
        if ((k==2) and (pos % 7 == 6)) continue;
        if (grid[next]) continue;
        if (visited2[next]) continue;
        dfs2(next);
    }

    return;
}

void dfs3(ll pos){
    if (visited[pos]) return;
    visited[pos] = true;

    REP(k,4){
        ll next = pos + dx[k];
        if (next >= 7*M) continue;
        if (next < 0) continue;
        if ((k==1) and (pos % 7 == 0)) continue;
        if ((k==2) and (pos % 7 == 6)) continue;
        if (grid[next]) continue;
        if (visited[next]) continue;
        dfs3(next);
    }

    return;
}
void dfs4(ll pos){
    if (visited2[pos]) return;
    visited2[pos] = true;

    REP(k,4){
        ll next = pos + dx[k];
        if (next >= 14*M) continue;
        if (next < 0) continue;
        if ((k==1) and (pos % 7 == 0)) continue;
        if ((k==2) and (pos % 7 == 6)) continue;
        if (grid[next % M]) continue;
        if (visited2[next]) continue;
        dfs4(next);
    }

    return;
}

void solve1(){
    ll count = 0;
    FORq(i,0,7*N-1){
        if ((grid[i] == false) and (visited[i] == false)){
            dfs0(i);
            count++;
        }
    }

    PRINTLLD(count);
    return;
}


void solve23(){
    ll count1 = 0;
    ll count2 = 0;

    FORq(i,0,M-1){
        if ((grid[i] == false) and (visited[i] == false)){
            dfs1(i);
            count1++;
        }
    }
    //printf("count1 = %lld\n",count1);

    FORq(i,0,2*M-1){
        if ((grid[i] == false) and (visited2[i] == false)){
            dfs2(i);
            count2++;
        }
    }

    //printf("count2 = %lld\n",count2);
    ll A,B;
    A = count2 - count1;
    B = count1 - A;
    ll c = 7*N / M;
    PRINTLLD(A*c + B);
    return;
}

void solve4(){
    ll count1 = 0;
    ll count2 = 0;
    FORq(i,0,7*M-1){
        if ((grid[i] == false) and (visited[i] == false)){
            dfs3(i);
            count1++;
        }
    }
    //printf("count1 = %lld\n",count1);

    FORq(i,0,14*M-1){
        if ((grid[i % M] == false) and (visited2[i] == false)){
            dfs4(i);
            count2++;
        }
    }

    ll A,B; A = count2 - count1;
    B = count1 - A;
    ll x = N/M;
    PRINTLLD(A*x + B);
}


int main(){
    SCLLD3(N,M,Q);
    ARSCD(a,Q);

    REP(q,Q){
        ll ai = a[q];
        ll k = 0;
        while(k*M + ai <= 700000 + 2 ){
            grid[k*M+ai] = true;
            k++;
        }
    }

    if (N <= 100000){ // #1
        solve1();
    } else if (M % 7 == 0){
        solve23();
    } else {
        solve4();
    }
}

Submission Info

Submission Time
Task C - Calendar 2
User Lithium
Language C++14 (GCC 5.4.1)
Score 500
Code Size 5131 Byte
Status AC
Exec Time 121 ms
Memory 15232 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:7:29: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll* {aka long long int*}’ [-Wformat=]
 #define SCD(n) scanf("%d",&n)
                             ^
./Main.cpp:15:29: note: in expansion of macro ‘SCD’
 #define ARSCD(A,N) REP(i,N){SCD(A[i]);}
                             ^
./Main.cpp:199:5: note: in expansion of macro ‘ARSCD’
     ARSCD(a,Q);
     ^
./Main.cpp:198:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     SCLLD3(N,M,Q);
                  ^
./Main.cpp:15:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 #define ARSCD(A,N) REP(i,N){SCD(A[i]);}
                                      ^
./Main.cpp:199:5: note: in expansion of macro ‘ARSCD’
     ARSCD(a,Q);
     ^

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 0 / 0 100 / 100 90 / 90 200 / 200 110 / 110
Status
AC × 2
AC × 7
AC × 1
AC × 3
AC × 12
Set Name Test Cases
Sample sub0_in1.txt, sub0_in2.txt
Subtask1 sub0_in1.txt, sub0_in2.txt, sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub1_in4.txt, sub1_in5.txt
Subtask2 sub2_in1.txt
Subtask3 sub2_in1.txt, sub3_in1.txt, sub3_in2.txt
Subtask4 sub0_in1.txt, sub0_in2.txt, sub1_in1.txt, sub1_in2.txt, sub1_in3.txt, sub1_in4.txt, sub1_in5.txt, sub2_in1.txt, sub3_in1.txt, sub3_in2.txt, sub4_in1.txt, sub4_in2.txt
Case Name Status Exec Time Memory
sub0_in1.txt AC 1 ms 2304 KB
sub0_in2.txt AC 1 ms 2304 KB
sub1_in1.txt AC 1 ms 2304 KB
sub1_in2.txt AC 1 ms 2304 KB
sub1_in3.txt AC 1 ms 2304 KB
sub1_in4.txt AC 2 ms 2304 KB
sub1_in5.txt AC 24 ms 14720 KB
sub2_in1.txt AC 10 ms 2560 KB
sub3_in1.txt AC 10 ms 2688 KB
sub3_in2.txt AC 9 ms 8064 KB
sub4_in1.txt AC 121 ms 5504 KB
sub4_in2.txt AC 74 ms 15232 KB