답안 #321703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
321703 2020-11-13T04:50:02 Z Kevin_Zhang_TW The Kingdom of JOIOI (JOI17_joioi) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template <class T, class ...U> 
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template <class T>
void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l) == r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

template <class T>
bool chmin(T &a, T b) { return b < a ? (a = b, true) : false; }
template <class T>
bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int MAX_N = 2010, inf = 1e9;
#define int ll
int n, m, a[MAX_N][MAX_N], res = inf;
struct bit {
	vector<vector<int>> v;
	int n, m;
	bit(int _n, int _m) :
		n(_n), m(_m), v(vector<vector<int>> (n+1, vector<int>(m+1)){
		}

	void add(int x, int y) {
		for (int i = x;i <= n;i += i&-i)
		   for (int j = y;j <= m;j += j&-j)
			   ++v[i][j];
	}
	int qry(int x, int y) {
		int res = 0;
		for (int i = x;i;i ^= i&-i)
			for (int j = y;j;j ^= j&-j)
				res += v[i][j];
		return res;
	}
};
		   		   
void update() {
	bit tree(n, m);
	
	vector<pair<int,int>> id;
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j)
			id.pb(i, j);

	auto get = [&](pair<int,int> p) {
		return a[p.first][p.second];
	};

	sort(AI(id), [&](auto x, auto y) {
			return get(x) < get(y);
			});

	auto valid = [&](pair<int,int> p) {
		assert(tree.qry(p.first, p.second) <= p.first * p.second);
		return tree.qry(p.first, p.second) == p.first * p.second;
	};

	for (int i = 0, j = 0;i+1 < id.size();++i) {
		tree.add(id[i].first, id[i].second);

		while (j <= i && valid(id[j]))
			++j;
		//DE(get(id[i]), get(id[0]));

		if (valid(id[0]) && valid(id[i]))
			chmin(res, max(get(id[i]) - get(id[0]), get(id.back()) - get(id[j])));
	}
	chmin(res, get(id.back()) - get(id.front()));
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for (int i = 1;i <= n;++i)
		for (int j = 1;j <= m;++j)
			cin >> a[i][j];
	update();

	for (int l = 1, r = n;l < r;++l, --r)
		swap(a[l], a[r]);

	update();

	swap(n, m);

	for (int i = 1;i <= n;++i)
		for (int j = i+1;j <= m;++j)
			swap(a[i][j], a[j][i]);

	update();
	for (int l = 1, r = n;l < r;++l, --r)
		swap(a[l], a[r]);
	update();

	cout << res << '\n';
}

Compilation message

joioi.cpp:105:1: error: expected '}' at end of input
  105 | }
      | ^
joioi.cpp:26:12: note: to match this '{'
   26 | struct bit {
      |            ^
joioi.cpp: In constructor 'bit::bit(ll, ll)':
joioi.cpp:30:62: error: expected ')' before '{' token
   30 |   n(_n), m(_m), v(vector<vector<int>> (n+1, vector<int>(m+1)){
      |                  ~                                           ^
      |                                                              )
joioi.cpp:45:1: error: expected '{' before '}' token
   45 | };
      | ^
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from joioi.cpp:1:
joioi.cpp: In lambda function:
joioi.cpp:64:15: error: 'struct bit' has no member named 'qry'
   64 |   assert(tree.qry(p.first, p.second) <= p.first * p.second);
      |               ^~~
joioi.cpp:65:15: error: 'struct bit' has no member named 'qry'
   65 |   return tree.qry(p.first, p.second) == p.first * p.second;
      |               ^~~
joioi.cpp: In member function 'void bit::update()':
joioi.cpp:68:28: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for (int i = 0, j = 0;i+1 < id.size();++i) {
      |                        ~~~~^~~~~~~~~~~
joioi.cpp:69:8: error: 'struct bit' has no member named 'add'
   69 |   tree.add(id[i].first, id[i].second);
      |        ^~~
joioi.cpp:71:25: error: could not convert 'valid.bit::update()::<lambda(std::pair<long long int, long long int>)>((*(const std::pair<long long int, long long int>*)(& id.std::vector<std::pair<long long int, long long int> >::operator[](((std::vector<std::pair<long long int, long long int> >::size_type)j)))))' from 'void' to 'bool'
   71 |   while (j <= i && valid(id[j]))
      |                    ~~~~~^~~~~~~
joioi.cpp:75:12: error: could not convert 'valid.bit::update()::<lambda(std::pair<long long int, long long int>)>((*(const std::pair<long long int, long long int>*)(& id.std::vector<std::pair<long long int, long long int> >::operator[](0))))' from 'void' to 'bool'
   75 |   if (valid(id[0]) && valid(id[i]))
      |       ~~~~~^~~~~~~
joioi.cpp:75:28: error: could not convert 'valid.bit::update()::<lambda(std::pair<long long int, long long int>)>((*(const std::pair<long long int, long long int>*)(& id.std::vector<std::pair<long long int, long long int> >::operator[](((std::vector<std::pair<long long int, long long int> >::size_type)i)))))' from 'void' to 'bool'
   75 |   if (valid(id[0]) && valid(id[i]))
      |                       ~~~~~^~~~~~~
joioi.cpp: In member function 'int32_t bit::main()':
joioi.cpp:105:1: warning: no return statement in function returning non-void [-Wreturn-type]
  105 | }
      | ^
joioi.cpp: At global scope:
joioi.cpp:105:1: error: expected unqualified-id at end of input