#include <bits/stdc++.h>
#define task "60131A"
#define ff first
#define ss second
using namespace std;
using ld = long double;
using ull = unsigned long long;
using ll = long long;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
const char el = '\n';
const char sp = ' ';
const ll inf = 1e9; //1e18;
const ll maxN = 1e6 + 1;
int n, m;
int l[maxN], cnt[maxN];
ll p[maxN];
vector <vector <ll>> a, b;
vector <vector <pll>> c;
deque <int> dq;
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen(task".inp", "r", stdin);
// freopen(task".out", "w", stdout);
cin >> n >> m;
a.resize(n, vector <ll> (m));
b.resize(n, vector <ll> (m));
for (int i = 0;i < n;++i)
{
bool ok = 1;
for (int j = 0;j < m;++j)
{
cin >> a[i][j];
ok &= (a[i][j] == 0);
}
if (ok) dq.push_back(i), cnt[i] = inf;
}
for (int i = 0;i < n;++i)
for (int j = 0;j < m;++j)
cin >> b[i][j];
c.resize(m, vector <pll> (n));
for (int j = 0;j < m;++j)
{
l[j] = 0;
for (int i = 0;i < n;++i)
c[j][i] = {a[i][j], i};
sort(c[j].begin(), c[j].end());
}
int ans = 0;
while(!dq.empty())
{
auto it = dq.front();
ans++;
dq.pop_front();
int i = it;
for (int j = 0;j < m;++j)
p[j] += b[i][j];
for (int j = 0;j < m;++j)
{
while(l[j] < n && c[j][l[j]].ff <= p[j])
{
int ii = c[j][l[j]].ss;
cnt[ii]++;
if (cnt[ii] == m) dq.push_back(ii);
l[j]++;
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
160 ms |
84508 KB |
Output is correct |
5 |
Correct |
158 ms |
84424 KB |
Output is correct |
6 |
Correct |
159 ms |
84680 KB |
Output is correct |
7 |
Correct |
129 ms |
75924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4696 KB |
Output is correct |
7 |
Correct |
3 ms |
4700 KB |
Output is correct |
8 |
Correct |
3 ms |
4700 KB |
Output is correct |
9 |
Correct |
2 ms |
4696 KB |
Output is correct |
10 |
Correct |
3 ms |
4700 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
4 ms |
5820 KB |
Output is correct |
4 |
Correct |
35 ms |
17044 KB |
Output is correct |
5 |
Correct |
33 ms |
17052 KB |
Output is correct |
6 |
Correct |
387 ms |
143184 KB |
Output is correct |
7 |
Correct |
369 ms |
143336 KB |
Output is correct |
8 |
Correct |
390 ms |
143328 KB |
Output is correct |
9 |
Correct |
363 ms |
143188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
3164 KB |
Output is correct |
4 |
Correct |
160 ms |
84508 KB |
Output is correct |
5 |
Correct |
158 ms |
84424 KB |
Output is correct |
6 |
Correct |
159 ms |
84680 KB |
Output is correct |
7 |
Correct |
129 ms |
75924 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
3 ms |
4700 KB |
Output is correct |
16 |
Correct |
2 ms |
4696 KB |
Output is correct |
17 |
Correct |
3 ms |
4700 KB |
Output is correct |
18 |
Correct |
3 ms |
4700 KB |
Output is correct |
19 |
Correct |
3 ms |
4700 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
4 ms |
5820 KB |
Output is correct |
23 |
Correct |
35 ms |
17044 KB |
Output is correct |
24 |
Correct |
33 ms |
17052 KB |
Output is correct |
25 |
Correct |
387 ms |
143184 KB |
Output is correct |
26 |
Correct |
369 ms |
143336 KB |
Output is correct |
27 |
Correct |
390 ms |
143328 KB |
Output is correct |
28 |
Correct |
363 ms |
143188 KB |
Output is correct |
29 |
Correct |
196 ms |
36164 KB |
Output is correct |
30 |
Correct |
199 ms |
35896 KB |
Output is correct |
31 |
Correct |
249 ms |
43572 KB |
Output is correct |
32 |
Correct |
147 ms |
36160 KB |
Output is correct |
33 |
Correct |
169 ms |
35920 KB |
Output is correct |
34 |
Correct |
199 ms |
36788 KB |
Output is correct |
35 |
Correct |
231 ms |
43576 KB |
Output is correct |
36 |
Correct |
199 ms |
37176 KB |
Output is correct |
37 |
Correct |
220 ms |
36784 KB |
Output is correct |
38 |
Correct |
156 ms |
43572 KB |
Output is correct |