Submission #1118700

#TimeUsernameProblemLanguageResultExecution timeMemory
1118700AvianshSquare or Rectangle? (NOI19_squarerect)C++17
89.24 / 100
2 ms512 KiB
#include "squarerect.h"
#include <bits/stdc++.h>
using namespace std;

bool sq(int i, int j){
    int lo = max(i-19,1);
    int hi = i;
    while(lo<hi){
        int mid = (lo+hi)/2;
        if(inside_shape(mid,j)){
            hi=mid;
        }
        else{
            lo=mid+1;
        }
    }
    int lim1 = lo;

    lo=max(j-19,1);
    hi=j;
    while(lo<hi){
        int mid = (lo+hi)/2;
        if(inside_shape(i,mid)){
            hi=mid;
        }
        else{
            lo=mid+1;
        }
    }
    int lim3 = lo;

    if(i>j){
        lo=i+1;
        hi=101;
        while(lo<hi){
            int mid = (lo+hi)/2;
            if(inside_shape(mid,j)){
                lo=mid+1;
            }
            else{
                hi=mid;
            }
        }
        int lim2 = lo;

        int dim1 = lim2-lim1;

        int lim4 = j+1;

        if(dim1+lim3-1>100)
            return 0;
        if(!inside_shape(i,dim1+lim3-1)){
            return 0;
        }
        if(dim1+lim3>100){
            return 1;
        }
        if(inside_shape(i,dim1+lim3)){
            return 0;
        }
        else{
            return 1;
        }
    }
    else{
        lo=j+1;
        hi=101;
        while(lo<hi){
            int mid = (lo+hi)/2;
            if(inside_shape(i,mid)){
                lo=mid+1;
            }
            else{
                hi=mid;
            }
        }
        int lim4 = lo;

        int dim2 = lim4-lim3;

        int lim2 = i+1;

        if(dim2+lim1-1>100)
            return 0;
        if(!inside_shape(dim2+lim1-1,j)){
            return 0;
        }
        if(dim2+lim1>100){
            return 1;
        }
        if(inside_shape(dim2+lim1,j)){
            return 0;
        }
        else{
            return 1;
        }
    }
    assert(0);
}

bool am_i_square(int n, int q) {
    assert(n==100);
    for(int i = 20;i<=100;i+=20){
        for(int j = 20;j<=100;j+=20){
            if(inside_shape(i,j)){
                return sq(i,j);
            }
        }
    }
    return 0;
}

Compilation message (stderr)

squarerect.cpp: In function 'bool sq(int, int)':
squarerect.cpp:48:13: warning: unused variable 'lim4' [-Wunused-variable]
   48 |         int lim4 = j+1;
      |             ^~~~
squarerect.cpp:81:13: warning: unused variable 'lim2' [-Wunused-variable]
   81 |         int lim2 = i+1;
      |             ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...