Submission #1118708

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

bool sq(int i, int j,int mxi, int mxj){
    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=mxi+1;
        hi=min(101,lo+19);
        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=mxj+1;
        hi=min(101,lo+19);
        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);
    int mini,mxi,minj,mxj;
    mini=101;
    mxi=0;
    minj=101;
    mxj=0;
    for(int i = 20;i<=80;i+=20){
        for(int j = 20;j<=100;j+=20){
            //cout << i << " " << j << "\n";
            if(inside_shape(i,j)){
                mini=min(mini,i);
                mxi=max(mxi,i);
                minj=min(minj,j);
                mxj=max(mxj,j);
            }
        }
    }
    if(mini!=101){
        return sq(mini,minj,mxi,mxj);
    }
    int i = 100;
    for(int j = 20;j<=100;j+=20){
        //cout << i << " " << j << "\n";
        if(inside_shape(i,j)){
            return sq(i,j,i,j);
        }
    }
    return 0;
}

Compilation message (stderr)

squarerect.cpp: In function 'bool sq(int, int, int, int)':
squarerect.cpp:47:13: warning: unused variable 'lim4' [-Wunused-variable]
   47 |         int lim4 = j+1;
      |             ^~~~
squarerect.cpp:80:13: warning: unused variable 'lim2' [-Wunused-variable]
   80 |         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...