結果

問題 No.755 Zero-Sum Rectangle
ユーザー wakannyaaiwakannyaai
提出日時 2020-03-09 13:13:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 325 ms / 2,000 ms
コード長 3,232 bytes
コンパイル時間 1,746 ms
コンパイル使用メモリ 171,648 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-25 10:24:19
合計ジャッジ時間 7,769 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 228 ms
5,248 KB
testcase_02 AC 166 ms
5,376 KB
testcase_03 AC 241 ms
5,376 KB
testcase_04 AC 276 ms
5,376 KB
testcase_05 AC 293 ms
5,376 KB
testcase_06 AC 190 ms
5,376 KB
testcase_07 AC 188 ms
5,376 KB
testcase_08 AC 248 ms
5,376 KB
testcase_09 AC 285 ms
5,376 KB
testcase_10 AC 325 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include <random>
#include <algorithm>
#include <unordered_set>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define cSort(a,cmp) sort(a.begin(),a.end(),cmp)
#define reSort(a) sort(a.rbegin(), a.rend())
static const ll llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const ll  llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const ll d_5 = 100000;
static const ll d9_7 = 1000000007;
static const ll d_9 = 1000000000;
static const double PI=3.14159265358979323846;

template<class T>
void Printvector(std::vector<T> a){
  int size = a.size();
  rep(i,size){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}
template<class T>
void Printvector(std::vector<std::vector<T>> a){
  int size = a.size();
  rep(i,size){
    int size2=a[i].size();
    rep(j,size2){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
template<class T>
vector<T> getaccum(vector<T> a){
  int size=a.size();
  vector<T> ans(size);
  ans[0]=a[0];
  for(int i=0;i<size-1;i++){
    ans[i+1]=ans[i]+a[i+1];
    //ans[i+1]%=d9_7;
  }
  return ans;
}
template<class T>
vector<vector<T>> getaccum2D(vector<vector<T>> a){
  int sizey=a.size();
  int sizex=a[0].size();
  vector<vector<T>> ans(sizey,vector<T>(sizex,0));
  //ans=a;
  ans[0][0]=a[0][0];
  for(int i=1;i<sizex;i++){
    ans[0][i]=ans[0][i-1]+a[0][i];
  }
  for(int i=1;i<sizex;i++){
    ans[i][0]=ans[i-1][0]+a[i][0];
  }
  for (int i = 0; i < sizey-1; i++)
        for (int j = 0; j < sizex-1; j++)
            ans[i+1][j+1] = ans[i][j+1] + ans[i+1][j] - ans[i][j] + a[i+1][j+1];
  return ans;
}
ll getaccumnum(vector<ll> accum,int l,int r){//閉区間[l,r]の総和
  if(l==0){
    return accum[r];
  }else{
    return accum[r]-accum[l-1];
  }
}
template<class T>
T getaccumnum2D(vector<vector<T>>& accum,int x1,int y1,int x2,int y2){//2の方が右下、閉区間
  
  T ans=accum[y2][x2];
  if(x1==0 && y1==0){
    ;
  }else if(x1>0 && y1==0){
    ans-=accum[y2][x1-1];
  }else if(x1==0 && y1>0){
    ans-=accum[y1-1][x2];
  }else{
    ans-=accum[y1-1][x2];
    ans-=accum[y2][x1-1];
    ans+=accum[y1-1][x1-1];
  }
  return ans;
}

int main(void){
  ll n,M;
  cin>>n>>M;
  vll m(M,vl(M));
  rep(i,M){
    rep(j,M){
      cin>>m[i][j];
    }
  }
  vi x(n),y(n);
  rep(i,n){
    cin>>y[i]>>x[i];
    x[i]--;
    y[i]--;
  }
  vll accum = getaccum2D(m);
  int ans=0;
          rep(i,n){
            ans=0;
  for(int x1=0;x1<=x[i];x1++){
    for(int x2=x[i];x2<M;x2++){
      for(int y1=0;y1<=y[i];y1++){
        for(int y2=y[i];y2<M;y2++){
            if(getaccumnum2D(accum,x1,y1,x2,y2)==0){
              ans++;
            }
          
        }
      }
    }
  }
  cout<<ans<<endl;
          }
  return 0;
}

//<<std::setprecision(30)

//重複削除
 /* std::sort(vec.begin(), vec.end());
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());*/
0