Submission #1520014
Source Code Expand
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 310;
int a[maxn][maxn];
bool ok[maxn];
int ct[maxn], pos[maxn];
int n, m;
bool check(int x)
{
bool tf = true;
memset(ok, true, sizeof ok);
memset(ct, 0, sizeof ct);
for (int i = 1;i <= n;++i)
{
pos[i] = 1;
ct[a[i][1]]++;
if (ct[a[i][1]] > x) tf = false;
}
if (tf) return true;
while (true)
{
for (int i = 1;i <= m;++i) if (ct[i] > x) ok[i] = false;
for (int i = 1;i <= n;++i)
{
while (pos[i] <= m && !ok[a[i][pos[i]]]) pos[i]++;
if (pos[i] == m + 1) return false;
}
tf = true;
memset(ct, 0, sizeof ct);
for (int i = 1;i <= n;++i)
{
ct[a[i][pos[i]]]++;
if (ct[a[i][pos[i]]] > x)
{
tf = false;
break;
}
}
if (tf) return true;
}
return false;
}
int main(int argc, char * argv[])
{
int ans;
scanf("%d%d", &n, &m);
for (int i = 1;i <= n;++i)
{
for (int j = 1;j <= m;++j)
{
scanf("%d", &a[i][j]);
}
}
ans = n;
int l = 1;
int r = n;
while (l <= r)
{
int mid = (l + r) >> 1;
if (check(mid))
{
ans = mid;
r = mid - 1;
}
else
{
l = mid + 1;
}
}
printf("%d\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Sports Festival |
User |
wrz91win |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1280 Byte |
Status |
AC |
Exec Time |
13 ms |
Memory |
512 KB |
Compile Error
./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:56:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:61:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i][j]);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
1 ms |
128 KB |
sample_02.txt |
AC |
1 ms |
128 KB |
sample_03.txt |
AC |
1 ms |
128 KB |
subtask_1_01.txt |
AC |
1 ms |
128 KB |
subtask_1_02.txt |
AC |
1 ms |
256 KB |
subtask_1_03.txt |
AC |
1 ms |
256 KB |
subtask_1_04.txt |
AC |
1 ms |
256 KB |
subtask_1_05.txt |
AC |
1 ms |
256 KB |
subtask_1_06.txt |
AC |
3 ms |
512 KB |
subtask_1_07.txt |
AC |
4 ms |
512 KB |
subtask_1_08.txt |
AC |
2 ms |
512 KB |
subtask_1_09.txt |
AC |
1 ms |
512 KB |
subtask_1_10.txt |
AC |
1 ms |
256 KB |
subtask_1_11.txt |
AC |
3 ms |
256 KB |
subtask_1_12.txt |
AC |
1 ms |
128 KB |
subtask_1_13.txt |
AC |
3 ms |
256 KB |
subtask_1_14.txt |
AC |
8 ms |
512 KB |
subtask_1_15.txt |
AC |
13 ms |
512 KB |
subtask_1_16.txt |
AC |
8 ms |
512 KB |
subtask_1_17.txt |
AC |
9 ms |
512 KB |
subtask_1_18.txt |
AC |
12 ms |
512 KB |