#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, k, cnt;
vector<ll> cur, p, vs, sm;
vector<vector<ll>> r, u;
vector<set<pair<ll, ll>>> s;
queue<ll> q;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>k;
cur.resize(k);
sm.resize(n);
s.resize(k);
p.resize(n);
vs.resize(n);
r.resize(n);
u.resize(n);
for (int i=0; i<n; i++) r[i].resize(k), u[i].resize(k);
for (int i=0; i<n; i++) for (int j=0; j<k; j++) cin>>r[i][j], sm[i]+=r[i][j];
for (int i=0; i<n; i++) for (int j=0; j<k; j++) cin>>u[i][j];
for (int i=0; i<n; i++) if (sm[i]==0) q.push(i), vs[i]=1;
for (int i=0; i<n; i++) if (!vs[i]) s[0].insert({r[i][0], i});
while (!q.empty())
{
auto x=q.front();
q.pop();
cnt++;
for (int i=0; i<k; i++)
{
cur[i]+=u[x][i];
while (!s[i].empty()&&s[i].begin()->first<=cur[i])
{
ll tmp=s[i].begin()->second;
s[i].erase(s[i].begin());
if (i==k-1) vs[tmp]=1, q.push(tmp);
else s[i+1].insert({r[tmp][i+1], tmp});
}
}
}
cout<<cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
1104 KB |
Output is correct |
4 |
Correct |
105 ms |
70740 KB |
Output is correct |
5 |
Correct |
110 ms |
70736 KB |
Output is correct |
6 |
Correct |
110 ms |
70736 KB |
Output is correct |
7 |
Correct |
98 ms |
70736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
4 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
7 ms |
2384 KB |
Output is correct |
4 |
Correct |
87 ms |
20040 KB |
Output is correct |
5 |
Correct |
58 ms |
19960 KB |
Output is correct |
6 |
Execution timed out |
1054 ms |
208456 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
1104 KB |
Output is correct |
4 |
Correct |
105 ms |
70740 KB |
Output is correct |
5 |
Correct |
110 ms |
70736 KB |
Output is correct |
6 |
Correct |
110 ms |
70736 KB |
Output is correct |
7 |
Correct |
98 ms |
70736 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
3 ms |
592 KB |
Output is correct |
15 |
Correct |
4 ms |
592 KB |
Output is correct |
16 |
Correct |
2 ms |
592 KB |
Output is correct |
17 |
Correct |
2 ms |
592 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
592 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
7 ms |
2384 KB |
Output is correct |
23 |
Correct |
87 ms |
20040 KB |
Output is correct |
24 |
Correct |
58 ms |
19960 KB |
Output is correct |
25 |
Execution timed out |
1054 ms |
208456 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |