Submission #8399718


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

int main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    vector<string> S(N); 
    rep(i,N) cin >> S[i];
    vector<vector<int>> blue(N+1,vector<int>(M+1,0));
    rep(i,N) rep(j,M) if (S[i][j]=='1') ++blue[i+1][j+1];
    rep(i,N+1) rep(j,M) blue[i][j+1]+=blue[i][j];
    vector<vector<int>> eh(N+1,vector<int>(M,0)),ew(N,vector<int>(M+1,0));
    rep(i,N) rep(j,M-1) if (S[i][j]=='1'&&S[i][j+1]=='1') ++eh[i+1][j+1];
    rep(i,N+1) rep(j,M-1) eh[i][j+1]+=eh[i][j];
    rep(j,M) rep(i,N-1) if (S[i][j]=='1'&&S[i+1][j]=='1') ++ew[i+1][j+1];
    rep(j,M+1) rep(i,N-1) ew[i+1][j]+=ew[i][j];
    rep(i,Q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int node=0,edge=0;
        rep2(i,a,c+1) node+=blue[i][d]-blue[i][b-1];
        rep2(i,a,c+1) edge+=eh[i][d-1]-eh[i][b-1];
        rep2(i,b,d+1) edge+=ew[c-1][i]-ew[a-1][i];
        cout << node-edge << endl;
    }
}

Submission Info

Submission Time
Task C - Nuske vs Phantom Thnook
User rniya
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1476 Byte
Status TLE
Exec Time 4207 ms
Memory 54144 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 21
TLE × 29
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt TLE 4205 ms 53888 KB
02.txt TLE 4206 ms 52096 KB
03.txt TLE 4206 ms 53888 KB
04.txt TLE 4206 ms 51840 KB
05.txt TLE 4206 ms 51840 KB
06.txt TLE 4205 ms 53760 KB
07.txt TLE 4206 ms 49408 KB
08.txt TLE 4205 ms 51968 KB
09.txt TLE 4206 ms 45056 KB
10.txt TLE 4207 ms 51968 KB
11.txt TLE 4206 ms 53632 KB
12.txt AC 3566 ms 20352 KB
13.txt AC 2346 ms 1664 KB
14.txt AC 593 ms 1280 KB
15.txt AC 447 ms 640 KB
16.txt AC 576 ms 1024 KB
17.txt AC 1772 ms 1408 KB
18.txt AC 889 ms 1024 KB
19.txt AC 728 ms 1024 KB
20.txt TLE 4206 ms 48512 KB
21.txt TLE 4206 ms 51584 KB
22.txt TLE 4206 ms 51968 KB
23.txt AC 636 ms 1536 KB
24.txt TLE 4206 ms 51968 KB
25.txt AC 455 ms 640 KB
26.txt AC 527 ms 896 KB
27.txt AC 740 ms 896 KB
28.txt AC 899 ms 1024 KB
29.txt AC 1777 ms 1408 KB
30.txt AC 582 ms 1024 KB
31.txt TLE 4206 ms 51840 KB
32.txt TLE 4206 ms 54144 KB
33.txt TLE 4206 ms 51840 KB
34.txt TLE 4207 ms 52096 KB
35.txt TLE 4205 ms 53632 KB
36.txt TLE 4206 ms 51840 KB
37.txt TLE 4205 ms 53760 KB
38.txt TLE 4206 ms 51840 KB
39.txt TLE 4207 ms 51840 KB
40.txt TLE 4206 ms 53760 KB
41.txt TLE 4207 ms 51712 KB
42.txt TLE 4206 ms 53888 KB
43.txt TLE 4207 ms 51584 KB
44.txt TLE 4207 ms 51840 KB
45.txt AC 1 ms 256 KB
46.txt AC 1 ms 256 KB
47.txt AC 1 ms 256 KB
48.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB