Submission #1281078

#TimeUsernameProblemLanguageResultExecution timeMemory
1281078jackofall718Square or Rectangle? (NOI19_squarerect)C++20
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
extern bool inside_shape(int X, int Y); 

bool am_i_square(int n, int Q) {        // must use int, not long long
    int start_x = -1;
    int start_y = -1;
    bool found = false;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (inside_shape(i, j)) {
                found = true;
                start_x = i;
                start_y = j;
                break;
            }
        }
        if (found) break;
    }

    ll left1 = start_x;
    ll right1 = n;
    ll ans1;
    ll ans2;
    ll left2=start_y;
    ll right2=n;
    while (left1 <= right1){

        ll mid = left1 + (right1-left1)/2;

        if (inside_shape(mid,start_y)){
            ans1 = mid;
            left1 = mid+1;
        }
        else{
            right1 = mid-1;
        }




    }
    while (left2 <= right2){

        ll mid = left2 + (right2-left2)/2;

        if (inside_shape(start_x,mid)){
            ans2 = mid;
            left1 = mid+1;
        }
        else{
            right2 = mid-1;
        }




    }
    ll left3 = 1;
    ll right3 = start_x;
    ll ans3;
    ll ans4;
    ll left4=1;
    ll right4=start_y;
    while (left3 <= right4){

        ll mid = left1 + (right1-left1)/2;

        if (inside_shape(mid,start_y)){
            ans3 = mid;
            left3 = mid+1;
        }
        else{
            right3 = mid-1;
        }




    }
    while (left4 <= right4){

        ll mid = left4 + (right4-left4)/2;

        if (inside_shape(start_x,mid)){
            ans4 = mid;
            left4 = mid+1;
        }
        else{
            right4 = mid-1;
        }




    }
    if (ans1+ans3==ans2+ans4)return true;
    else return false;
    


    

    
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...