Submission #538793

# Submission time Handle Problem Language Result Execution time Memory
538793 2022-03-17T18:26:09 Z beaconmc Quality Of Living (IOI10_quality) C++14
0 / 100
2906 ms 98316 KB
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;

#define ll int

ll pos[10000000][2];
ll pref[5001][5001];
ll r, c, h, w;

bool check(ll x){
    FOR(i,0,5002){
        FOR(j,0,5002){
            pref[i][j] = 0;
        }
    }
    FOR(i,1,x+1){
        ll a = pos[i][0];
        ll b = pos[i][1];
        pref[a+1][b+1] += 1;
        pref[max(0, a+1-h)][b+1] -= 1;
        pref[a+1][max(0, b+1-w)] -= 1;
        pref[max(0, a+1-h)][max(0, b+1-w)] += 1;

        FOR(i,0,5002){
            FOR(j,1,5002){
                pref[i][j] += pref[i-1][j];
            }
        }
        FOR(i,0,5002){
            FOR(j,1,5002){
                pref[j][i] += pref[j-1][i];
            }
        }

        FOR(i,0,5002){
            FOR(j,0,5002){
                if (pref[i][j] >= (r+c)/2){
                    return true;
                }
            }
        }
        return false;
        
    }
}

int rectangle(int R, int C, int H, int W, int Q[3001][3001]) {
    r = R; c = C; h = H; w = W;
    FOR(i,0,R){
        FOR(j,0,C){
            pos[Q[i][j]][0] = i;
            pos[Q[i][j]][1] = j;
        }
    }
 
    int lo = 0;
    int hi = int(R*C/2)+1;
    while (lo < hi) {
		int mid = lo + (hi - lo) / 2;
		if (check(mid)) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}
	return lo;
}

Compilation message

quality.cpp: In function 'bool check(int)':
quality.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
   48 | }
      | ^
quality.cpp:16:24: warning: iteration 5001 invokes undefined behavior [-Waggressive-loop-optimizations]
   16 |             pref[i][j] = 0;
      |             ~~~~~~~~~~~^~~
quality.cpp:3:33: note: within this loop
    3 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   15 |         FOR(j,0,5002){
      |             ~~~~~~~~             
quality.cpp:15:9: note: in expansion of macro 'FOR'
   15 |         FOR(j,0,5002){
      |         ^~~
quality.cpp:29:28: warning: iteration 5000 invokes undefined behavior [-Waggressive-loop-optimizations]
   29 |                 pref[i][j] += pref[i-1][j];
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~~~
quality.cpp:3:33: note: within this loop
    3 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   28 |             FOR(j,1,5002){
      |                 ~~~~~~~~         
quality.cpp:28:13: note: in expansion of macro 'FOR'
   28 |             FOR(j,1,5002){
      |             ^~~
quality.cpp:34:28: warning: iteration 5000 invokes undefined behavior [-Waggressive-loop-optimizations]
   34 |                 pref[j][i] += pref[j-1][i];
      |                 ~~~~~~~~~~~^~~~~~~~~~~~~~~
quality.cpp:3:33: note: within this loop
    3 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   33 |             FOR(j,1,5002){
      |                 ~~~~~~~~         
quality.cpp:33:13: note: in expansion of macro 'FOR'
   33 |             FOR(j,1,5002){
      |             ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2906 ms 98316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2906 ms 98316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2906 ms 98316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2906 ms 98316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2906 ms 98316 KB Output isn't correct
2 Halted 0 ms 0 KB -