Submission #1447265
Source Code Expand
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0)
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}
int n, m, a[333][333], cnt[333], last[333], ban[333];
inline bool check(int mid) {
memset(last, 0, sizeof last);
memset(ban, 0, sizeof ban);
rep(i, 1, n) last[i] = 1;
while(1) {
bool ok = 1;
memset(cnt, 0, sizeof cnt);
rep(i, 1, n) {
cnt[a[i][last[i]]]++;
if(cnt[a[i][last[i]]] > mid || ban[a[i][last[i]]]) ok = 0;
}
if(ok) return 1;
rep(i, 1, n) {
if(cnt[a[i][last[i]]] > mid || ban[a[i][last[i]]]) {
if(last[i] == n) return 0;
ban[a[i][last[i]]] = 1;
last[i]++;
}
}
}
assert(0);
}
int main() {
#ifdef accepted
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
onlycin;
cin >> n >> m;
rep(i, 1, n) {
rep(j, 1, m) cin >> a[i][j];
}
int l = 0, r = n + 1;
while(r - l > 1) {
int mid = l + r >> 1;
if(check(mid)) r = mid;
else l = mid;
}
cout << r << nxtl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Sports Festival |
User |
cmaster |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1926 Byte |
Status |
AC |
Exec Time |
13 ms |
Memory |
640 KB |
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 |
256 KB |
sample_02.txt |
AC |
1 ms |
256 KB |
sample_03.txt |
AC |
1 ms |
256 KB |
subtask_1_01.txt |
AC |
1 ms |
256 KB |
subtask_1_02.txt |
AC |
1 ms |
384 KB |
subtask_1_03.txt |
AC |
1 ms |
384 KB |
subtask_1_04.txt |
AC |
2 ms |
384 KB |
subtask_1_05.txt |
AC |
1 ms |
384 KB |
subtask_1_06.txt |
AC |
4 ms |
640 KB |
subtask_1_07.txt |
AC |
6 ms |
640 KB |
subtask_1_08.txt |
AC |
3 ms |
640 KB |
subtask_1_09.txt |
AC |
3 ms |
640 KB |
subtask_1_10.txt |
AC |
2 ms |
256 KB |
subtask_1_11.txt |
AC |
2 ms |
384 KB |
subtask_1_12.txt |
AC |
1 ms |
256 KB |
subtask_1_13.txt |
AC |
3 ms |
384 KB |
subtask_1_14.txt |
AC |
8 ms |
640 KB |
subtask_1_15.txt |
AC |
13 ms |
640 KB |
subtask_1_16.txt |
AC |
8 ms |
640 KB |
subtask_1_17.txt |
AC |
9 ms |
640 KB |
subtask_1_18.txt |
AC |
11 ms |
640 KB |