답안 #878145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878145 2023-11-24T06:06:05 Z _unknown_2010 Chessboard (IZhO18_chessboard) C++17
0 / 100
147 ms 262144 KB
//#ifndef LOCAL
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#endif

#include <bits/stdc++.h>
using namespace std;
using vecp = vector<pair<int,int>>;
#define vecm(a,n,m) vector<vector<int>>a(n,vector<int>(m,0));
#define int int64_t
#define pb  push_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mpii map<int,int>
#define lb lower_bound
#define ub upper_bound
#define foor(i,a,b) for(int i=a;i<b; i++)
#define foor(i,a) foor(i,0,a)
#define ins insert
#define ss second
#define ff first
#define until(x, a) for (auto x : a)
#define ln(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define seea(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define seev(v,n) for(int i=0;i<n;i++){int x; cin>>x; v.push_back(x);}
const int mod = 1E9+7;
void solution(){
    int n,k;
    cin >> n >> k;
    vector<vector<int>> vec(n,vector<int>(n,0));
    vector<int> mx;
    while(k--){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;d--;
        for(int i=a; i<=c; i++){
            for(int j=b; j<=d; j++){
                vec[i][j]=1;
            }
        }
    }
    int cnt=0;
    for(int i=1; i<=n/2; i++){
        if(n%i==0){
            int x=n/i;
            int f=INT_MAX,s=INT_MAX;
            if(x%2==0){
                f=(i*i)*(x/2)*n;
            }
            else {
                s=x/2*(x/2+1)*2*(i*i);
            }
            for(int k=0; k<n; k++){
                for(int j=0; j<n; j++){
                    int fg=k/i+1;
                    int sg=j/i+1;
                    if(vec[k][j]==1){
                        if(fg%2==sg%2){
                            s++;f--;
                        }
                        else {
                            f++;s--;
                        }
                    }
                }
            }
            mx.push_back(f);
            mx.push_back(s);
        }
    }
    sort(all(mx));
    cout << mx[0];
}
int32_t main(){
    clock_t tStart = clock();
    std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q = 1;  cin >> q;
    while(q--) {
        solution();
        cout << '\n';
    }
    cerr<<fixed<<setprecision(3)<<"\nTime Taken: "<<(double)(clock()- tStart)/CLOCKS_PER_SEC<<endl;
}
/*

██╗  ██╗ █████╗  ██████╗     ██╗██╗   ██╗ ██████╗████████╗
██║░░██║██╔══██╗██╔════╝░░░░░██║██║░░░██║██╔════╝╚══██╔══╝
███████║██║░░██║╚█████╗░░░░░░██║██║░░░██║╚█████╗░░░░██║░░░
██╔══██║██║░░██║░╚═══██╗██╗░░██║██║░░░██║░╚═══██╗░░░██║░░░
██║░░██║╚█████╔╝██████╔╝╚█████╔╝╚██████╔╝██████╔╝░░░██║░░░
╚═╝░░╚═╝░╚════╝░╚═════╝░░╚════╝░░╚═════╝░╚═════╝░░░░╚═╝░░░
*/

Compilation message

chessboard.cpp:19: warning: "foor" redefined
   19 | #define foor(i,a) foor(i,0,a)
      | 
chessboard.cpp:18: note: this is the location of the previous definition
   18 | #define foor(i,a,b) for(int i=a;i<b; i++)
      | 
chessboard.cpp: In function 'void solution()':
chessboard.cpp:44:9: warning: unused variable 'cnt' [-Wunused-variable]
   44 |     int cnt=0;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 147 ms 444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 92 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 92 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 147 ms 444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -