답안 #242429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242429 2020-06-27T16:16:54 Z AmineWeslati Square or Rectangle? (NOI19_squarerect) C++14
32 / 100
5 ms 256 KB
//Never stop trying
#include "squarerect.h"
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//s.order_of_key(), *s.find_by_order()

using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
//#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e7;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

int NN;
char g[101][101];

/*bool inside_shape(int x, int y){
   cout << x << ' ' << y << endl;
   if(g[x][y]=='*') return true;
   return false;
}*/




bool am_i_square(int N, int Q){
   int mnx=INF,mny=INF,mxx=-1,mxy=-1;

   for(int i=20; i<=80; i+=20) for(int j=20; j<=80; j+=20) if(inside_shape(i,j)){
      mnx=min(mnx,i); mny=min(mny,j); mxx=max(mxx,i); mxy=max(mxy,j);
   }

   if(mxx!=-1){
      int l=mnx-20+1,r=mnx;
      while(l<r){
         int m=(l+r)/2;
         if(!inside_shape(m,mny)) l=m+1;
         else r=m;
      }
      mnx=l;
      //cout << mnx << endl;

      l=mny-20+1;r=mny;
      while(l<r){
         int m=(l+r)/2;
         if(!inside_shape(mnx,m)) l=m+1;
         else r=m;
      }
      mny=l;
      //cout << mny << endl;

      l=mxx; r=mxx+20;
      while(l<r){
         int m=(l+r+1)/2;
         if(!inside_shape(m,mny)) r=m-1;
         else l=m;
      }
      mxx=l;
      //cout << mxx << endl;

      if(100-mny<mxx-mnx) return false;
      if(!inside_shape(mnx,mny+mxx-mnx)) return false;
      if(mny+mxx-mnx+1==101) return true;
      if(inside_shape(mnx,mny+mxx-mnx+1)) return false;
      return true;
   }

   else{
      int nb=0;
      int x,y;
      for(int i=20; i<=100; i+=20) if(inside_shape(i,100)){
         nb++;
         x=i; y=100;
      }
      if(nb>1) return false;

      if(nb>0){
         int l=x-20+1,r=x;
         while(l<r){
            int m=(l+r)/2;
            if(!inside_shape(m,y)) l=m+1;
            else r=m;
         }
         x=l;

         if(x+19>100) return false;
         if(!inside_shape(x+19,y)) return false;
         if(x+20==101) return true;
         if(inside_shape(x+20,y)) return false;
         return true;
      }

      for(int j=20; j<=80; j++) if(inside_shape(100,j)){
         nb++;
         x=100; y=j;
      }
      if(nb>1 || !nb) return false;

      int l=y-20+1,r=y;
      while(l<r){
         int m=(l+r)/2;
         if(!inside_shape(x,m)) l=m+1;
         else r=m;
      }
      y=l;

      if(y+19>100) return false;
      if(!inside_shape(x,y+19)) return false;
      if(y+20==101) return true;
      if(inside_shape(x,y+20)) return false;
      return true;
   }
}

/*int32_t main(){
   boost;
   NN=100;
   for(int i=1; i<=NN; i++) for(int j=1; j<=NN; j++) g[i][j]='.';
   for(int i=1; i<=100; i++) for(int j=1; j<=100; j++) g[i][j]='*';
   if(am_i_square(NN,50)) cout << "yes" << endl;
   else cout << "aaaaaaaaaaaaaaaaaaaaaaaaaaa333333" << endl;


   return 0;
}*/

/*
5 5
.....
.....
.....
.....
**...
*/

Compilation message

squarerect.cpp: In function 'bool am_i_square(int, int)':
squarerect.cpp:112:14: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
          int l=x-20+1,r=x;
              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Wrong Answer.
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Wrong Answer. Used too many queries.