Submission #1446755


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, M;
int A[300][300];

bool solve(int x) {
	int p[300] = {}; // 見ている箇所 -1:終了
	bool done[300] = {}; // 飛ばしたスポーツ
	bool succ[300] = {}; // okなスポーツ
	
	while (true) {
		int cnt[300] = {};
		
		REP(i, N) if (p[i] != -1) {
			while (p[i] < M && done[ A[i][p[i]] ]) p[i]++;
			if (p[i] == M) return false;
			cnt[ A[i][p[i]] ]++;
		}
		
		vector<pii> v; // 人数, スポーツid
		REP(i, M) if (cnt[i] != 0) v.push_back(pii(cnt[i], i));
		if (v.empty()) break;
		
		sort(ALL(v), greater<pii>());
		
		bool f = false;
		REP(i, v.size()) {
			if (v[i].fi > x) {
				done[v[i].se] = true;
				f = true;
			}
		}
		if (f) continue;
		
		REP(i, v.size()) {
			succ[v[i].se] = true;
			done[v[i].se] = true;
		}
		
		REP(i, N) if (p[i] != -1 && succ[ A[i][p[i]] ]) p[i] = -1;
	}
	
	REP(i, N) if (p[i] != -1) return false;
	return true;
}

int main() {
	cin >> N >> M;
	REP(i, N) REP(j, M) scanf("%d", &A[i][j]), A[i][j]--;
	
	int l = 0, r = M + 1;
	
	while (r - l > 1) {
		int m = (r + l) / 2;
		
		if (solve(m)) r = m;
		else l = m;
	}
	
	cout << max(r, 1) << endl;
	
	return 0;
}

Submission Info

Submission Time
Task B - Sports Festival
User tkmst201
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1835 Byte
Status WA
Exec Time 14 ms
Memory 640 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:66:54: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  REP(i, N) REP(j, M) scanf("%d", &A[i][j]), A[i][j]--;
                                                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 19
WA × 5
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 WA 1 ms 384 KB
subtask_1_03.txt AC 2 ms 256 KB
subtask_1_04.txt AC 2 ms 384 KB
subtask_1_05.txt WA 1 ms 384 KB
subtask_1_06.txt AC 3 ms 640 KB
subtask_1_07.txt WA 5 ms 640 KB
subtask_1_08.txt WA 3 ms 640 KB
subtask_1_09.txt WA 1 ms 640 KB
subtask_1_10.txt AC 2 ms 256 KB
subtask_1_11.txt AC 3 ms 256 KB
subtask_1_12.txt AC 1 ms 256 KB
subtask_1_13.txt AC 4 ms 384 KB
subtask_1_14.txt AC 9 ms 640 KB
subtask_1_15.txt AC 14 ms 640 KB
subtask_1_16.txt AC 9 ms 640 KB
subtask_1_17.txt AC 9 ms 640 KB
subtask_1_18.txt AC 12 ms 640 KB