Submission #378506

# Submission time Handle Problem Language Result Execution time Memory
378506 2021-03-17T01:06:06 Z daniel920712 Chessboard (IZhO18_chessboard) C++14
39 / 100
50 ms 9708 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
int all[1005][1005]={0};
int sum[1005][1005]={0};
int main()
{
    int N,M,ans=2e9,t,a,b,c,d,i,j,k;
    scanf("%d %d",&N,&M);
    while(M--)
    {
        scanf("%d %d %d %d",&a,&b,&c,&d);
        for(i=a;i<=c;i++) for(j=b;j<=d;j++) all[i][j]=1;
    }
    for(i=1;i<=N;i++) for(j=1;j<=N;j++) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+all[i][j];
    for(i=1;i<N;i++)
    {
        if(N%i==0)
        {
            t=0;
            for(j=1;j<=N/i;j++)
            {
                for(k=1;k<=N/i;k++)
                {
                    if((j+k)%2) t+=sum[i*j][i*k]-sum[i*j][i*(k-1)]-sum[i*(j-1)][i*k]+sum[i*(j-1)][i*(k-1)];
                    else t+=(i*i)-(sum[i*j][i*k]-sum[i*j][i*(k-1)]-sum[i*(j-1)][i*k]+sum[i*(j-1)][i*(k-1)]);
                }
            }
            ans=min(ans,t);
            t=0;
            for(j=1;j<=N/i;j++)
            {
                for(k=1;k<=N/i;k++)
                {
                    if((j+k)%2==0) t+=sum[i*j][i*k]-sum[i*j][i*(k-1)]-sum[i*(j-1)][i*k]+sum[i*(j-1)][i*(k-1)];
                    else t+=(i*i)-(sum[i*j][i*k]-sum[i*j][i*(k-1)]-sum[i*(j-1)][i*k]+sum[i*(j-1)][i*(k-1)]);
                }
            }
            ans=min(ans,t);

        }
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
chessboard.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         scanf("%d %d %d %d",&a,&b,&c,&d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 876 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 876 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 876 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1004 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1132 KB Output is correct
10 Correct 1 ms 876 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 876 KB Output is correct
15 Correct 1 ms 768 KB Output is correct
16 Correct 22 ms 8300 KB Output is correct
17 Correct 44 ms 9580 KB Output is correct
18 Correct 50 ms 9708 KB Output is correct
19 Correct 46 ms 9324 KB Output is correct
20 Correct 49 ms 9452 KB Output is correct
21 Correct 42 ms 9580 KB Output is correct
22 Correct 12 ms 5740 KB Output is correct
23 Correct 29 ms 8684 KB Output is correct
24 Correct 46 ms 9580 KB Output is correct
25 Correct 17 ms 8064 KB Output is correct
26 Correct 32 ms 8812 KB Output is correct
27 Correct 40 ms 9068 KB Output is correct
28 Correct 47 ms 9452 KB Output is correct
29 Correct 23 ms 8556 KB Output is correct
30 Correct 13 ms 7916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 748 KB Output is correct
5 Correct 1 ms 748 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Runtime error 1 ms 492 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -