結果

問題 No.2684 折々の色
ユーザー AerenAeren
提出日時 2024-03-20 22:13:22
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 13,370 bytes
コンパイル時間 3,777 ms
コンパイル使用メモリ 270,636 KB
実行使用メモリ 32,440 KB
最終ジャッジ日時 2024-09-30 08:08:30
合計ジャッジ時間 18,946 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 3 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 2 ms
5,248 KB
testcase_11 AC 308 ms
20,352 KB
testcase_12 AC 102 ms
15,104 KB
testcase_13 AC 305 ms
24,460 KB
testcase_14 AC 151 ms
13,440 KB
testcase_15 AC 166 ms
17,664 KB
testcase_16 AC 31 ms
7,680 KB
testcase_17 AC 110 ms
13,952 KB
testcase_18 AC 295 ms
27,420 KB
testcase_19 AC 297 ms
24,192 KB
testcase_20 AC 181 ms
14,848 KB
testcase_21 AC 90 ms
10,112 KB
testcase_22 AC 363 ms
28,416 KB
testcase_23 AC 229 ms
16,768 KB
testcase_24 AC 141 ms
12,160 KB
testcase_25 AC 153 ms
14,080 KB
testcase_26 AC 287 ms
21,080 KB
testcase_27 AC 222 ms
14,976 KB
testcase_28 AC 212 ms
16,640 KB
testcase_29 AC 354 ms
30,336 KB
testcase_30 AC 327 ms
30,464 KB
testcase_31 AC 351 ms
31,104 KB
testcase_32 AC 402 ms
30,976 KB
testcase_33 AC 341 ms
30,848 KB
testcase_34 AC 413 ms
31,152 KB
testcase_35 AC 408 ms
31,468 KB
testcase_36 AC 334 ms
30,700 KB
testcase_37 AC 448 ms
31,744 KB
testcase_38 AC 514 ms
32,256 KB
testcase_39 AC 511 ms
32,300 KB
testcase_40 AC 498 ms
32,284 KB
testcase_41 AC 513 ms
32,384 KB
testcase_42 AC 512 ms
32,440 KB
testcase_43 AC 511 ms
32,364 KB
testcase_44 AC 506 ms
32,256 KB
testcase_45 AC 515 ms
32,304 KB
testcase_46 AC 502 ms
32,364 KB
testcase_47 AC 2 ms
5,248 KB
testcase_48 AC 2 ms
5,248 KB
testcase_49 AC 2 ms
5,248 KB
testcase_50 AC 2 ms
5,248 KB
testcase_51 AC 1 ms
5,248 KB
testcase_52 AC 1 ms
5,248 KB
testcase_53 AC 2 ms
5,248 KB
testcase_54 AC 1 ms
5,248 KB
testcase_55 AC 2 ms
5,248 KB
testcase_56 AC 2 ms
5,248 KB
testcase_57 AC 2 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif

template<class data_t, data_t _mod>
struct modular_fixed_base{
#define IS_INTEGRAL(T) (is_integral_v<T> || is_same_v<T, __int128_t> || is_same_v<T, __uint128_t>)
#define IS_UNSIGNED(T) (is_unsigned_v<T> || is_same_v<T, __uint128_t>)
	static_assert(IS_UNSIGNED(data_t));
	static_assert(_mod >= 1);
	static constexpr bool VARIATE_MOD_FLAG = false;
	static constexpr data_t mod(){
		return _mod;
	}
	template<class T>
	static vector<modular_fixed_base> precalc_power(T base, int SZ){
		vector<modular_fixed_base> res(SZ + 1, 1);
		for(auto i = 1; i <= SZ; ++ i) res[i] = res[i - 1] * base;
		return res;
	}	
	static vector<modular_fixed_base> _INV;
	static void precalc_inverse(int SZ){
		if(_INV.empty()) _INV.assign(2, 1);
		for(auto x = _INV.size(); x <= SZ; ++ x) _INV.push_back(_mod / x * -_INV[_mod % x]);
	}
	// _mod must be a prime
	static modular_fixed_base _primitive_root;
	static modular_fixed_base primitive_root(){
		if(_primitive_root) return _primitive_root;
		if(_mod == 2) return _primitive_root = 1;
		if(_mod == 998244353) return _primitive_root = 3;
		data_t divs[20] = {};
		divs[0] = 2;
		int cnt = 1;
		data_t x = (_mod - 1) / 2;
		while(x % 2 == 0) x /= 2;
		for(auto i = 3; 1LL * i * i <= x; i += 2){
			if(x % i == 0){
				divs[cnt ++] = i;
				while(x % i == 0) x /= i;
			}
		}
		if(x > 1) divs[cnt ++] = x;
		for(auto g = 2; ; ++ g){
			bool ok = true;
			for(auto i = 0; i < cnt; ++ i){
				if(modular_fixed_base(g).power((_mod - 1) / divs[i]) == 1){
					ok = false;
					break;
				}
			}
			if(ok) return _primitive_root = g;
		}
	}
	constexpr modular_fixed_base(){ }
	modular_fixed_base(const double &x){ data = _normalize(llround(x)); }
	modular_fixed_base(const long double &x){ data = _normalize(llround(x)); }
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> modular_fixed_base(const T &x){ data = _normalize(x); }
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> static data_t _normalize(const T &x){
		int sign = x >= 0 ? 1 : -1;
		data_t v =  _mod <= sign * x ? sign * x % _mod : sign * x;
		if(sign == -1 && v) v = _mod - v;
		return v;
	}
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> operator T() const{ return data; }
	modular_fixed_base &operator+=(const modular_fixed_base &otr){ if((data += otr.data) >= _mod) data -= _mod; return *this; }
	modular_fixed_base &operator-=(const modular_fixed_base &otr){ if((data += _mod - otr.data) >= _mod) data -= _mod; return *this; }
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> modular_fixed_base &operator+=(const T &otr){ return *this += modular_fixed_base(otr); }
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr> modular_fixed_base &operator-=(const T &otr){ return *this -= modular_fixed_base(otr); }
	modular_fixed_base &operator++(){ return *this += 1; }
	modular_fixed_base &operator--(){ return *this += _mod - 1; }
	modular_fixed_base operator++(int){ modular_fixed_base result(*this); *this += 1; return result; }
	modular_fixed_base operator--(int){ modular_fixed_base result(*this); *this += _mod - 1; return result; }
	modular_fixed_base operator-() const{ return modular_fixed_base(_mod - data); }
	modular_fixed_base &operator*=(const modular_fixed_base &rhs){
		if constexpr(is_same_v<data_t, unsigned int>) data = (unsigned long long)data * rhs.data % _mod;
		else if constexpr(is_same_v<data_t, unsigned long long>){
			long long res = data * rhs.data - _mod * (unsigned long long)(1.L / _mod * data * rhs.data);
			data = res + _mod * (res < 0) - _mod * (res >= (long long)_mod);
		}
		else data = _normalize(data * rhs.data);
		return *this;
	}
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>
	modular_fixed_base &inplace_power(T e){
		if(e == 0) return *this = 1;
		if(data == 0) return *this = {};
		if(data == 1 || e == 1) return *this;
		if(data == mod() - 1) return e % 2 ? *this : *this = -*this;
		if(e < 0) *this = 1 / *this, e = -e;
		if(e == 1) return *this;
		modular_fixed_base res = 1;
		for(; e; *this *= *this, e >>= 1) if(e & 1) res *= *this;
		return *this = res;
	}
	template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>
	modular_fixed_base power(T e) const{
		return modular_fixed_base(*this).inplace_power(e);
	}
	modular_fixed_base &operator/=(const modular_fixed_base &otr){
		make_signed_t<data_t> a = otr.data, m = _mod, u = 0, v = 1;
		if(a < _INV.size()) return *this *= _INV[a];
		while(a){
			make_signed_t<data_t> t = m / a;
			m -= t * a; swap(a, m);
			u -= t * v; swap(u, v);
		}
		assert(m == 1);
		return *this *= u;
	}
#define ARITHMETIC_OP(op, apply_op)\
modular_fixed_base operator op(const modular_fixed_base &x) const{ return modular_fixed_base(*this) apply_op x; }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
modular_fixed_base operator op(const T &x) const{ return modular_fixed_base(*this) apply_op modular_fixed_base(x); }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
friend modular_fixed_base operator op(const T &x, const modular_fixed_base &y){ return modular_fixed_base(x) apply_op y; }
	ARITHMETIC_OP(+, +=) ARITHMETIC_OP(-, -=) ARITHMETIC_OP(*, *=) ARITHMETIC_OP(/, /=)
#undef ARITHMETIC_OP
#define COMPARE_OP(op)\
bool operator op(const modular_fixed_base &x) const{ return data op x.data; }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
bool operator op(const T &x) const{ return data op modular_fixed_base(x).data; }\
template<class T, typename enable_if<IS_INTEGRAL(T)>::type* = nullptr>\
friend bool operator op(const T &x, const modular_fixed_base &y){ return modular_fixed_base(x).data op y.data; }
	COMPARE_OP(==) COMPARE_OP(!=) COMPARE_OP(<) COMPARE_OP(<=) COMPARE_OP(>) COMPARE_OP(>=)
#undef COMPARE_OP
	friend istream &operator>>(istream &in, modular_fixed_base &number){
		long long x;
		in >> x;
		number.data = modular_fixed_base::_normalize(x);
		return in;
	}
//#define _SHOW_FRACTION
	friend ostream &operator<<(ostream &out, const modular_fixed_base &number){
		out << number.data;
	#if defined(LOCAL) && defined(_SHOW_FRACTION)
		cerr << "(";
		for(auto d = 1; ; ++ d){
			if((number * d).data <= 1000000){
				cerr << (number * d).data;
				if(d != 1) cerr << "/" << d;
				break;
			}
			else if((-number * d).data <= 1000000){
				cerr << "-" << (-number * d).data;
				if(d != 1) cerr << "/" << d;
				break;
			}
		}
		cerr << ")";
	#endif
		return out;
	}
	data_t data = 0;
#undef _SHOW_FRACTION
#undef IS_INTEGRAL
#undef IS_UNSIGNED
};
template<class data_t, data_t _mod> vector<modular_fixed_base<data_t, _mod>> modular_fixed_base<data_t, _mod>::_INV;
template<class data_t, data_t _mod> modular_fixed_base<data_t, _mod> modular_fixed_base<data_t, _mod>::_primitive_root;

const unsigned int mod = (119 << 23) + 1; // 998244353
// const unsigned int mod = 1e9 + 7; // 1000000007
// const unsigned int mod = 1e9 + 9; // 1000000009
// const unsigned long long mod = (unsigned long long)1e18 + 9;
using modular = modular_fixed_base<decay_t<decltype(mod)>, mod>;

// Requires modular
template<class modular_t, class len_t, bool ALLOW_BINEXP>
struct hash_base{
#ifdef LOCAL
	#define ASSERT(c) assert(c)
#else
	#define ASSERT(c) 42
#endif
	static modular_t _base, _inv_base;
	template<class T = int>
	static void setup(T base = 0){
		if constexpr(modular_t::VARIATE_MOD_FLAG) modular_t::setup((unsigned long long)1e18 + 9);
		if(!base) base = mt19937_64(chrono::high_resolution_clock::now().time_since_epoch().count())() % (long long)1e17 + (long long)9e17;
		_base = base, _inv_base = modular_t(1) / base;
	}
	static vector<modular_t> _power, _inv_power;
	static void setup_power(size_t len){
		if(_power.empty()) _power.push_back(1), _inv_power.push_back(1);
		while((int)_power.size() <= len){
			_power.push_back(_power.back() * _base);
			_inv_power.push_back(_inv_power.back() * _inv_base);
		}
	}
	static modular_t power(len_t e){
		assert(e >= 0);
		if constexpr(ALLOW_BINEXP) return e < (int)_power.size() ? _power[e] : _base.power(e);
		else{
			if((int)_power.size() <= e) setup_power(e);
			return _power[e];
		}
	}
	static modular_t inv_power(len_t e){
		assert(e >= 0);
		if constexpr(ALLOW_BINEXP) return e < (int)_inv_power.size() ? _inv_power[e] : _inv_base.power(e);
		else{
			if((int)_power.size() <= e) setup_power(e);
			return _inv_power[e];
		}
	}
	hash_base(){ ASSERT(_base >= 1); }
	hash_base(const modular_t &x, len_t len): data(x), len(len){ ASSERT(_base >= 1); }
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	hash_base(T x): data(x), len(1){ ASSERT(_base >= 1); }
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	hash_base(const vector<T> &s){
		ASSERT(_base >= 1);
		for(auto c: s) *this += hash_base(c);
	}
	hash_base(const string &s){
		ASSERT(_base >= 1);
		for(auto c: s) *this += hash_base(c);
	}
	hash_base &operator=(const hash_base &x){
		data = x.data, len = x.len;
		return *this;
	}
	hash_base &operator+=(const hash_base &x){
		data = power(x.len) * data + x.data;
		len += x.len;
		return *this;
	}
	hash_base operator+(const hash_base &x) const{ return hash_base(*this) += x; }
	hash_base &inplace_append_right(const hash_base &x){ return *this += x; }
	hash_base append_right(const hash_base &x) const{ return hash_base(*this).inplace_append_right(x); }
	hash_base &inplace_append_left(const hash_base &x){
		data += power(len) * x.data;
		len += x.len;
		return *this;
	}
	hash_base append_left(const hash_base &x) const{ return hash_base(*this).inplace_append_left(x); }
	hash_base &inplace_pop_right(const hash_base &x){
		assert(len >= x.len);
		data = inv_power(x.len) * (data - x.data);
		len -= x.len;
		return *this;
	}
	hash_base pop_right(const hash_base &x) const{ return hash_base(*this).inplace_pop_right(x); }
	hash_base &inplace_pop_left(const hash_base &x){
		assert(len >= x.len);
		data -= power(len - x.len) * x.data;
		len -= x.len;
		return *this;
	}
	hash_base pop_left(const hash_base &x) const{ return hash_base(*this).inplace_pop_left(x); }
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	hash_base &inplace_update(len_t pos, T x){
		assert(0 <= pos && pos < len);
		data += power(len - pos - 1) * x;
		return *this;
	}
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	hash_base update(len_t pos, T x) const{ return hash_base(*this).inplace_update(pos, x); }
	hash_base &inplace_update(len_t pos, const hash_base &x){
		assert(0 <= pos && pos + x.len <= len);
		data += power(len - pos - x.len) * x.data;
		return *this;
	}
	hash_base update(len_t pos, const hash_base &x) const{ return hash_base(*this).inplace_update(pos, x); }
#define COMPARE_OP(op)\
bool operator op(const hash_base &x) const{ return data op x.data; }
	COMPARE_OP(==) COMPARE_OP(!=) COMPARE_OP(<) COMPARE_OP(<=) COMPARE_OP(>) COMPARE_OP(>=)
#undef COMPARE_OP
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	hash_base &operator*=(T x){
		assert(x >= 0);
		if(x == 0) return *this = {};
		if(x == 1) return *this;
		hash_base res{};
		for(auto e = x; e; e >>= 1){
			if(e & 1) res += *this;
			*this += *this;
		}
		return *this = res;
	}
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	hash_base operator*(T x) const{ return hash_base(*this) *= x; }
	template<class T, typename enable_if<is_integral_v<T>>::type* = nullptr>
	friend hash_base operator*(T x, const hash_base &h){ return hash_base(h) *= x; }
	friend ostream &operator<<(ostream &out, const hash_base &x){ return out << "{" << x.data << ", " << x.len << "}"; }
	modular_t data = 0;
	len_t len = 0;
#undef ASSERT
};
template<class modular_t, class len_t, bool ALLOW_BINEXP> modular_t hash_base<modular_t, len_t, ALLOW_BINEXP>::_base;
template<class modular_t, class len_t, bool ALLOW_BINEXP> modular_t hash_base<modular_t, len_t, ALLOW_BINEXP>::_inv_base;
template<class modular_t, class len_t, bool ALLOW_BINEXP> vector<modular_t> hash_base<modular_t, len_t, ALLOW_BINEXP>::_power{1};
template<class modular_t, class len_t, bool ALLOW_BINEXP> vector<modular_t> hash_base<modular_t, len_t, ALLOW_BINEXP>::_inv_power{1};

using hash_t = hash_base<modular_fixed_base<unsigned long long, (unsigned long long)1e18 + 9>, int, false>;

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	hash_t::setup();
	int n, m;
	cin >> n >> m;
	vector<long long> obj(m);
	copy_n(istream_iterator<int>(cin), m, obj.begin());
	vector card(n, vector<int>(m));
	vector<int> opac(n);
	vector<map<hash_t, int>> appear(101);
	for(auto i = 0; i < n; ++ i){
		copy_n(istream_iterator<int>(cin), m, card[i].begin());
		cin >> opac[i];
		++ appear[opac[i]][hash_t{card[i]}];
	}
	for(auto i = 0; i < n; ++ i){
		hash_t cur{card[i]};
		for(auto op = 1; op <= 100; ++ op){
			hash_t x;
			for(auto j = 0; j < m; ++ j){
				int value = obj[j] * 100 * 100 - opac[i] * (100 - op) * card[i][j];
				if(value % (100 * op)){
					goto FAIL;
				}
				x += value / 100 / op;
			}
			if(appear[op][x] > (x == cur)){
				cout << "Yes\n";
				return 0;
			}
			FAIL:;
		}
	}
	cout << "No\n";
	return 0;
}

/*

*/
0