Submission #310387

# Submission time Handle Problem Language Result Execution time Memory
310387 2020-10-06T19:47:31 Z JovanK26 Luxury burrow (IZhO13_burrow) C++14
100 / 100
1162 ms 18168 KB
#include <bits/stdc++.h>

using namespace std;
int n,m,k,rez;
int prt[1001];
int sz[1001];
vector<int> nextt[1001];
int mat[1001][1001];
int cur[1001];
int findd(int x)
{
    while(x!=prt[x])
    {
        prt[x]=prt[prt[x]];
        x=prt[x];
    }
    return x;
}
void unionn(int x,int y)
{
    x=findd(x);
    y=findd(y);
    if(x==y)return;
    if(sz[x]<sz[y])swap(x,y);
    prt[y]=x;
    sz[x]+=sz[y];
    sz[y]=0;
}
void solve(int ind)
{
   for(int i=0;i<=m;i++)
   {
       nextt[i].clear();
   }
   for(int i=1;i<=n;i++)
   {
       nextt[cur[i]-ind].push_back(i);
   }
   for(int i=1;i<=n;i++)
   {
       prt[i]=-1;
       sz[i]=1;
   }
   for(int j=m;j>=1;j--)
   {
       for(int i=0;i<nextt[j].size();i++)
       {
           int f=nextt[j][i];
           prt[f]=f;
           if(f>1 && prt[f-1]!=-1)
           {
               unionn(f,f-1);
           }
           if(f<n && prt[f+1]!=-1)
           {
               unionn(f,f+1);
           }
           rez=max(rez,j*sz[findd(f)]);
       }
   }
}
int check(int x)
{
    rez=0;
    for(int i=1;i<=n;i++)
    {
        cur[i]=m+1;
    }
    for(int j=m;j>=1;j--)
    {
        for(int i=1;i<=n;i++)
        {
            if(mat[i][j]<x)cur[i]=j;
        }
        solve(j);
    }
    return rez;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin >> mat[i][j];
        }
    }
    int l=1;
    int r=1000000000;
    int med;
    while(l<=r)
    {
        med=(l+r)/2;
        if(check(med)>=k)
        {
            l=med+1;
        }
        else
        {
            r=med-1;
        }
    }
    cout << l-1 << ' '<<check(l-1);
    return 0;
}

Compilation message

burrow.cpp: In function 'void solve(int)':
burrow.cpp:46:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |        for(int i=0;i<nextt[j].size();i++)
      |                    ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 7 ms 768 KB Output is correct
9 Correct 14 ms 1408 KB Output is correct
10 Correct 27 ms 1548 KB Output is correct
11 Correct 69 ms 2176 KB Output is correct
12 Correct 28 ms 2560 KB Output is correct
13 Correct 49 ms 1152 KB Output is correct
14 Correct 106 ms 2936 KB Output is correct
15 Correct 109 ms 2808 KB Output is correct
16 Correct 141 ms 3864 KB Output is correct
17 Correct 118 ms 2816 KB Output is correct
18 Correct 370 ms 6500 KB Output is correct
19 Correct 392 ms 5624 KB Output is correct
20 Correct 776 ms 9720 KB Output is correct
21 Correct 834 ms 13944 KB Output is correct
22 Correct 1162 ms 18168 KB Output is correct
23 Correct 1152 ms 18168 KB Output is correct
24 Correct 568 ms 7672 KB Output is correct
25 Correct 580 ms 7288 KB Output is correct