Submission #375139

# Submission time Handle Problem Language Result Execution time Memory
375139 2021-03-09T03:36:00 Z Kevin_Zhang_TW Naan (JOI19_naan) C++17
Compilation error
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)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#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 
const int MAX_N = 2005;

int n, L;
int v[MAX_N][MAX_N];

struct frac {
	ll up, dn;
	void ref() { ll g = gcd(up, dn); up/=g, dn/=g; }
	frac(ll a, ll b) :
		up(a), dn(b) {}
	frac(ll v) :
		up(v), dn(1) {}
	void sca(ll v) { up *= v, dn *= v; }
};
frac operator * (frac a, frac b) { a.up *= b.up, a.dn *= b.dn, a.ref(); return a; }
frac operator * (frac a, ll v) { a.up *= v; return a; }
frac operator / (frac a, ll v) { a.dn *= v; return a; }
frac operator + (frac a, frac b) {
	ll da = a.dn, db = b.dn, nd = da / gcd(da, db) * db;
	a.sca(nd/da), b.sca(nd/db);
	a.up += b.up;
	return a;
}
frac operator - (frac a, frac b) { 
	ll da = a.dn, db = b.dn, nd = da / gcd(da, db) * db;
	a.sca(nd/da), b.sca(nd/db);
	a.up -= b.up;
	return a;
}

frac& operator += (frac &a, frac b) { return a = a + b; }
frac& operator -= (frac &a, frac b) { return a = a - b; }

bool operator < (frac a, frac b) { return a.up * b.dn < b.up * a.dn; }
bool operator > (frac a, frac b) { return a.up * b.dn > b.up * a.dn; }
ostream& operator << (ostream& out, frac a) { return out << a.up << ' ' << a.dn; }


int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> L;
	for (int i = 0;i < n;++i)
		for (int j = 0;j < L;++j)
			cin >> v[i][j];

	vector<int> od(n); iota(AI(od), 0);

	random_device rd;
	mt19937 gen(rd);

	int holan = 5000;
	do {
		// gen 
		bool ok = true;
		vector<frac> sep {{0, 1}};
		debug(AI(od));
		for (int x : od) {
			int sum = 0;
			for (int j = 0;j < L;++j)
				sum += v[x][j];

			auto [up, dn] = sep.back();

			int atid = up / dn, lft = dn - up % dn;
			DE(x, atid, lft, dn);

			frac need{sum, n};

			if (frac(lft, dn) * v[x][atid] > need) {
				frac len = need / v[x][atid];
				sep.pb(len + sep.back());
				continue;
			}
			need -= frac(lft, dn) * v[x][atid];
			++atid;
			while (atid < L) {
				if (need < v[x][atid]) break;
				need -= v[x][atid++];
			}
			if (atid == L && need > frac(0)) {
				ok = false;
				break;
			}
			sep.pb( frac(atid) + need / v[x][atid] );
			DE(sep.back());
		}
		if (!ok) continue;
		for (int i = 1;i < n;++i)
			cout << sep[i] << '\n';
		for (int i = 0;i < n;++i)
			cout << od[i]+1 << " \n"[i+1==n];
		return 0;
	} while (shuffle(AI(od), gen), holan--);

	cout << -1 << '\n';
}

Compilation message

naan.cpp: In function 'int32_t main()':
naan.cpp:65:16: error: no matching function for call to 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::mersenne_twister_engine(std::random_device&)'
   65 |  mt19937 gen(rd);
      |                ^
In file included from /usr/include/c++/9/random:49,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:108,
                 from naan.cpp:1:
/usr/include/c++/9/bits/random.h:530:9: note: candidate: 'template<class _Sseq, class> std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mersenne_twister_engine(_Sseq&)'
  530 |         mersenne_twister_engine(_Sseq& __q)
      |         ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/random.h:530:9: note:   template argument deduction/substitution failed:
/usr/include/c++/9/bits/random.h: In substitution of 'template<class _UIntType, long unsigned int __w, long unsigned int __n, long unsigned int __m, long unsigned int __r, _UIntType __a, long unsigned int __u, _UIntType __d, long unsigned int __s, _UIntType __b, long unsigned int __t, _UIntType __c, long unsigned int __l, _UIntType __f> template<class _Sseq> using _If_seed_seq = typename std::enable_if<std::__detail::__is_seed_seq<_Sseq, std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>, _UIntType>::value>::type [with _Sseq = std::random_device; _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253]':
/usr/include/c++/9/bits/random.h:528:32:   required from here
/usr/include/c++/9/bits/random.h:491:8: error: 'class std::random_device' has no member named 'generate'
  491 |  using _If_seed_seq = typename enable_if<__detail::__is_seed_seq<
      |        ^~~~~~~~~~~~
/usr/include/c++/9/bits/random.h:519:7: note: candidate: 'std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mersenne_twister_engine(std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type) [with _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253; std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type = long unsigned int]'
  519 |       mersenne_twister_engine(result_type __sd)
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/random.h:519:43: note:   no known conversion for argument 1 from 'std::random_device' to 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'}
  519 |       mersenne_twister_engine(result_type __sd)
      |                               ~~~~~~~~~~~~^~~~
/usr/include/c++/9/bits/random.h:516:7: note: candidate: 'std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mersenne_twister_engine() [with _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253]'
  516 |       mersenne_twister_engine() : mersenne_twister_engine(default_seed) { }
      |       ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/random.h:516:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/9/bits/random.h:461:11: note: candidate: 'constexpr std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::mersenne_twister_engine(const std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&)'
  461 |     class mersenne_twister_engine
      |           ^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/9/bits/random.h:461:11: note:   no known conversion for argument 1 from 'std::random_device' to 'const std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&'
/usr/include/c++/9/bits/random.h:461:11: note: candidate: 'constexpr std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::mersenne_twister_engine(std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&&)'
/usr/include/c++/9/bits/random.h:461:11: note:   no known conversion for argument 1 from 'std::random_device' to 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>&&'
naan.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
naan.cpp:72:3: note: in expansion of macro 'debug'
   72 |   debug(AI(od));
      |   ^~~~~
naan.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
naan.cpp:81:4: note: in expansion of macro 'DE'
   81 |    DE(x, atid, lft, dn);
      |    ^~
naan.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
naan.cpp:101:4: note: in expansion of macro 'DE'
  101 |    DE(sep.back());
      |    ^~