square869120Contest #4

Submission #1294716

Source codeソースコード

/***********************************************
#
#      Filename: c.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-05-19 23:53:20
***********************************************/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
int m, q;
bool vis[100000 + 10];
bool bao[100000 + 10][7];
bool used[100000 + 10][7];

void paint(int base, int mm) {
    for (int i = 0; i < mm; ++ i) {
        if (vis[i % m]) {
            int r = i / 7;
            int c = i % 7;
            bao[r + base][c] = true;
        }
    }
}

int dir[4][2] = {{-1,0}, {0,1}, {1,0}, {0,-1}};
void dfs(int x, int y, int rmax) {
    used[x][y] = true;
    for (int i = 0; i < 4; ++ i) {
        int nx = x + dir[i][0];
        int ny = y + dir[i][1];
        if (nx>=0 && nx<rmax && ny>=0 && ny<7 && !used[nx][ny] && !bao[nx][ny]) {
            dfs(nx, ny, rmax);
        }
    }
}

int main()
{
    cin >> n >> m >> q;
    int r;
    for (int i = 0; i < q; ++ i) {
        cin >> r;
        vis[r] = true;
    }

    int mm = m;
    if (m % 7) mm *= 7;

    paint(0, mm);
    int count1 = 0;
    for (int i = 0; i < mm/7; ++ i) {
        for (int j = 0; j < 7; ++ j) {
            if (!bao[i][j] && !used[i][j]) {
                dfs(i, j, mm/7);
                ++ count1;
            }
        }
    }

    paint(mm/7, mm);
    int count2 = 0;
    memset(used, false, sizeof(used));
    for (int i = 0; i < 2*mm/7; ++ i) {
        for (int j = 0; j < 7; ++ j) {
            if (!bao[i][j] && !used[i][j]) {
                dfs(i, j, 2*mm/7);
                ++ count2;
            }
        }
    }

    cout << count1 * 1L + (count2 - count1) * 1L * (n / (mm/7) - 1L) << endl;
    return 0;
}

Submission

Task問題 C - Calendar 2
User nameユーザ名 comsyl
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 RE
Score得点 290
Source lengthソースコード長 1822 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - sub0_in1.txt,sub0_in2.txt
Subtask1 0 / 100 sub0_in1.txt,sub0_in2.txt,sub1_in1.txt,sub1_in2.txt,sub1_in3.txt,sub1_in4.txt,sub1_in5.txt
Subtask2 90 / 90 sub2_in1.txt
Subtask3 200 / 200 sub2_in1.txt,sub3_in1.txt,sub3_in2.txt
Subtask4 0 / 110 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sub0_in1.txt AC 1 ms 896 KB
sub0_in2.txt AC 1 ms 896 KB
sub1_in1.txt AC 1 ms 896 KB
sub1_in2.txt AC 1 ms 896 KB
sub1_in3.txt AC 1 ms 896 KB
sub1_in4.txt AC 1 ms 896 KB
sub1_in5.txt RE
sub2_in1.txt AC 33 ms 1152 KB
sub3_in1.txt AC 16 ms 1280 KB
sub3_in2.txt AC 9 ms 5632 KB
sub4_in1.txt RE
sub4_in2.txt RE