#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define speed cin.tie (0) -> sync_with_stdio (0);ios_base::sync_with_stdio(false);cin.tie(0);
void solve()
{
int n, m, k;
cin>>n>>m>>k;
int a[n + 5][m + 5];
for(int i=0; i<n; i++)
{
for(int j=0; j<m; j++)
{
cin>>a[i][j];
}
}
bool v[n + m + 5] = {};
for(int j=0; j<m; j++)
{
pair<int, int> mx = {0, 0};
int f[n + m + 5] = {};
for(int i=0; i<n; i++)
{
int idx = 0;
while(idx < m && v[a[i][idx]]) idx++;
if (idx == m) continue;
f[a[i][idx]]++;
if (f[a[i][idx]] == mx.first && a[i][j] < mx.second) mx = {f[a[i][idx]], a[i][j]};
if (f[a[i][idx]] > mx.first) mx = {f[a[i][idx]], a[i][j]};
}
v[mx.second] = 1;
if (j == 0) cout<<mx.second<<endl;
if (v[k])
{
cout<<j<<endl;
break;
}
}
}
signed main ()
{
speed
// freopen("feast.in", "r", stdin);
// freopen("feast.out", "w", stdout);
int _ = 1;
// cin>>_;
while(_--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Partially correct |
0 ms |
348 KB |
Partially correct |
3 |
Partially correct |
0 ms |
344 KB |
Partially correct |
4 |
Partially correct |
1 ms |
348 KB |
Partially correct |
5 |
Partially correct |
0 ms |
348 KB |
Partially correct |
6 |
Partially correct |
0 ms |
348 KB |
Partially correct |
7 |
Partially correct |
0 ms |
600 KB |
Partially correct |
8 |
Partially correct |
0 ms |
348 KB |
Partially correct |
9 |
Partially correct |
0 ms |
348 KB |
Partially correct |
10 |
Partially correct |
0 ms |
348 KB |
Partially correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Partially correct |
0 ms |
344 KB |
Partially correct |
13 |
Partially correct |
0 ms |
348 KB |
Partially correct |
14 |
Partially correct |
1 ms |
348 KB |
Partially correct |
15 |
Partially correct |
0 ms |
348 KB |
Partially correct |
16 |
Partially correct |
0 ms |
348 KB |
Partially correct |
17 |
Partially correct |
0 ms |
344 KB |
Partially correct |
18 |
Partially correct |
1 ms |
348 KB |
Partially correct |
19 |
Partially correct |
0 ms |
348 KB |
Partially correct |
20 |
Partially correct |
0 ms |
348 KB |
Partially correct |