QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#285346#7940. Impossible Numbersucup-team088#TL 9ms12356kbC++177.9kb2023-12-16 17:59:592023-12-16 17:59:59

Judging History

你现在查看的是最新测评结果

  • [2023-12-17 13:41:15]
  • hack成功,自动添加数据
  • (/hack/501)
  • [2023-12-16 17:59:59]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:12356kb
  • [2023-12-16 17:59:59]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000009;
const int mod17 = 1000000007;
const ll INF = (ll)mod17 * mod17;
typedef pair<int, int>P;

#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;

using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
	vector<T> res;
	int ida = 0, idb = 0;
	while (ida < a.size() || idb < b.size()) {
		if (idb == b.size()) {
			res.push_back(a[ida]); ida++;
		}
		else if (ida == a.size()) {
			res.push_back(b[idb]); idb++;
		}
		else {
			if (a[ida] < b[idb]) {
				res.push_back(a[ida]); ida++;
			}
			else {
				res.push_back(b[idb]); idb++;
			}
		}
	}
	return res;
}
template<typename T>
void cinarray(vector<T>& v) {
	rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
	rep(i, v.size()) {
		if (i > 0)cout << " "; cout << v[i];
	}
	cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	//if (x == 0)return 0;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
//mod should be <2^31
struct modint {
	int n;
	modint() :n(0) { ; }
	modint(ll m) {
		if (m < 0 || mod <= m) {
			m %= mod; if (m < 0)m += mod;
		}
		n = m;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

ll gcd(ll a, ll b) {
	a = abs(a); b = abs(b);
	if (a < b)swap(a, b);
	while (b) {
		ll r = a % b; a = b; b = r;
	}
	return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
	if (loc >= v.size())v.resize(loc + 1, 0);
	v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
	fill(isp + 2, isp + mn, true);
	for (int i = 2; i < mn; i++) {
		if (!isp[i])continue;
		ps.push_back(i);
		for (int j = 2 * i; j < mn; j += i) {
			isp[j] = false;
		}
	}
}*/

//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	if (res == st.begin())return st.end();
	res--; return res;
}

//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
	auto res = st.lower_bound(val);
	return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
	return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
	a = a + b; return a;
}
mP operator-(mP a, mP b) {
	return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
	a = a - b; return a;
}
LP operator+(LP a, LP b) {
	return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
	a = a + b; return a;
}
LP operator-(LP a, LP b) {
	return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
	a = a - b; return a;
}

mt19937 mt(time(0));

const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };

//------------------------------------


void solve() {
	int n, k; cin >> n >> k;
	vector<int> a(n);
	rep(i, n) {
		rep(j, 6) {
			int x; cin >> x;
			a[i] |= (1 << x);
		}
	}
	vector<int> s(1 << 10);
	rep(i, (1 << 10)) {
		rep(j, n) {
			if (a[j] & i)s[i]++;
		}
	}
	vector<int> rs(1 << 10);
	rep(i, 1 << 10) {
		rs[i] = mod17;
		rep(j, 10) {
			if (i & (1 << j))continue;
			chmin(rs[i], s[1 << j]);
		}
	}
	vector<vector<int>> ss(10);
	rep(i, (1 << 10))rep(j, 10)if (i & (1 << j)) {
		ss[j].push_back(i);
	}
	
	vector<string> ans;
	string cur;
	vector<int> rest = s;
	vector<int> ids;
	function<void(int)> dfs = [&]( int cr) {
		if (ids.empty())return;
		/*if (cur == "1" && cr == 2) {
			cout << "hello\n";
			cout << mi << "\n";
		}*/
		if (cr == 0) {
			ans.push_back(cur);
			return;
			/*string cop = cur;
			sort(all(cop));
			if (cop[0] == '0' && cop.back() == '0')return;
			if (cop[0] == '0') {
				rep(i, cop.size())if (cop[i] != '0') {
					swap(cop[0], cop[i]);
					break;
				}
			}
			do {
				ans.push_back(cop);
			} while (ans.size() < k && next_permutation(all(cop)));
			return;*/
		}
		rep(i, 10) {
			cur.push_back('0' + i);
			vector<int> cop = ids;
			ids.clear();
			for (int id : cop) {
				if (id & (1 << i)) {
					rest[id]--;
				}
				if (cr - 1 > rest[id]) {
					ids.push_back(id);
				}
			}
			dfs(cr - 1);
			if (ans.size() == k)return;
			for (int id : cop) {
				if (id & (1 << i)) {
					rest[id]++;
				}
			}
			swap(ids, cop);
			cur.pop_back();
		}
	};
	rep(i, (1 << 10)) {
		bool ad = true;
		rep(j, (1 << 10))if(i!=j) {
			if ((j & i) == i) {
				if (s[i] == s[j]) {
					ad = false;
				}
			}
		}
		if(ad)ids.push_back(i);
	}
	for (int len = 1;; len++) {
		rep1(i, 9) {
			cur.push_back('0' + i);
			vector<int> cop = ids;
			ids.clear();
			for (int id : cop) {
				if (id & (1 << i)) {
					rest[id]--;
				}
				if (len - 1 > rest[id]) {
					ids.push_back(id);
				}
			}
			dfs(len - 1);
			if (ans.size() == k)break;
			for (int id : cop) {
				if (id & (1 << i)) {
					rest[id]++;
				}
			}
			ids = cop;
			cur.pop_back();
		}
		if (ans.size() == k)break;
	}
	//cout << ans.size() << "\n";
	coutarray(ans);
}



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed<<setprecision(10);
	//init_f();
	//init();
	//while(true)
	//expr();
	//int t; cin >> t; rep(i, t)
	solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11920kb

input:

2 3
1 8 7 0 6 2
1 2 5 4 9 3

output:

33 34 35

result:

ok single line: '33 34 35'

Test #2:

score: 0
Accepted
time: 5ms
memory: 11940kb

input:

1 10
1 5 2 2 6 4

output:

3 7 8 9 10 11 12 13 14 15

result:

ok single line: '3 7 8 9 10 11 12 13 14 15'

Test #3:

score: 0
Accepted
time: 5ms
memory: 11972kb

input:

4 10
1 5 7 1 2 4
0 1 5 8 9 4
3 5 2 2 7 8
6 1 7 0 2 2

output:

33 66 99 133 166 199 233 266 299 303

result:

ok single line: '33 66 99 133 166 199 233 266 299 303'

Test #4:

score: 0
Accepted
time: 5ms
memory: 12168kb

input:

5 10
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4

output:

7 17 27 37 47 55 57 67 70 71

result:

ok single line: '7 17 27 37 47 55 57 67 70 71'

Test #5:

score: 0
Accepted
time: 5ms
memory: 11952kb

input:

5 10
8 7 1 4 8 9
2 5 0 1 0 1
9 5 5 3 9 7
6 0 0 2 3 1
1 0 0 4 9 3

output:

66 88 166 188 222 226 262 266 288 366

result:

ok single line: '66 88 166 188 222 226 262 266 288 366'

Test #6:

score: 0
Accepted
time: 4ms
memory: 12164kb

input:

5 10
6 8 7 7 0 0
0 5 1 9 4 1
5 9 6 9 5 4
0 4 6 9 1 6
2 8 7 4 4 0

output:

3 13 22 23 30 31 32 33 34 35

result:

ok single line: '3 13 22 23 30 31 32 33 34 35'

Test #7:

score: 0
Accepted
time: 0ms
memory: 11940kb

input:

5 1000
0 4 1 3 9 6
9 6 2 1 8 6
5 3 0 7 7 3
0 2 8 0 8 4
2 4 1 2 9 7

output:

55 155 255 333 335 353 355 455 505 515 525 533 535 545 550 551 552 553 554 555 556 557 558 559 565 575 577 585 595 655 666 755 757 775 777 855 888 955 1055 1111 1116 1119 1155 1161 1166 1169 1191 1196 1199 1255 1333 1335 1353 1355 1455 1505 1515 1525 1533 1535 1545 1550 1551 1552 1553 1554 1555 1556...

result:

ok single line: '55 155 255 333 335 353 355 455...0 10053 10055 10111 10116 10119'

Test #8:

score: 0
Accepted
time: 6ms
memory: 12288kb

input:

5 10000
1 4 7 5 6 0
2 3 8 4 9 0
1 2 8 8 3 0
7 9 9 7 2 9
4 7 1 9 3 6

output:

55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 566 575 585 595 655 656 665 666 755 855 888 955 1055 1111 1115 1116 1151 1155 1156 1161 1165 1166 1255 1355 1455 1505 1511 1515 1516 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1561 1565 1566 1575...

result:

ok single line: '55 155 255 355 455 505 515 525...6 45507 45508 45509 45510 45511'

Test #9:

score: 0
Accepted
time: 7ms
memory: 12072kb

input:

6 10000
0 1 3 2 4 7
7 6 4 8 7 9
5 5 7 2 3 9
8 4 6 1 6 4
2 4 9 9 0 7
1 2 3 3 2 0

output:

55 155 255 355 455 505 515 525 535 545 550 551 552 553 554 555 556 557 558 559 565 575 585 595 655 666 668 686 688 755 855 866 868 886 888 955 1055 1111 1155 1255 1355 1455 1505 1515 1525 1535 1545 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1565 1575 1585 1595 1655 1666 1668 1686 1688 1755 18...

result:

ok single line: '55 155 255 355 455 505 515 525...6 66847 66848 66849 66850 66851'

Test #10:

score: 0
Accepted
time: 5ms
memory: 11996kb

input:

7 1000
5 2 1 6 3 7
7 9 8 1 8 1
8 7 2 0 6 2
3 8 6 0 5 1
8 8 3 7 0 8
1 0 6 3 5 6
6 7 5 0 9 1

output:

4 14 24 34 40 41 42 43 44 45 46 47 48 49 54 64 74 84 94 104 114 124 134 140 141 142 143 144 145 146 147 148 149 154 164 174 184 194 204 214 222 224 234 240 241 242 243 244 245 246 247 248 249 254 264 274 284 294 304 314 324 334 340 341 342 343 344 345 346 347 348 349 354 364 374 384 394 400 401 402 ...

result:

ok single line: '4 14 24 34 40 41 42 43 44 45 4...3 3474 3475 3476 3477 3478 3479'

Test #11:

score: 0
Accepted
time: 5ms
memory: 12156kb

input:

8 1000
3 8 1 9 7 6
6 5 2 1 8 9
3 8 7 9 2 3
0 5 7 7 7 3
2 9 0 4 2 9
2 7 5 0 5 3
5 9 2 7 0 8
8 3 1 3 0 5

output:

44 144 244 344 404 414 424 434 440 441 442 443 444 445 446 447 448 449 454 464 474 484 494 544 644 666 744 844 944 1044 1111 1116 1144 1161 1166 1244 1344 1404 1414 1424 1434 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1454 1464 1474 1484 1494 1544 1611 1616 1644 1661 1666 1744 1844 1944 2044 ...

result:

ok single line: '44 144 244 344 404 414 424 434...4 14540 14541 14542 14543 14544'

Test #12:

score: 0
Accepted
time: 9ms
memory: 12356kb

input:

9 10000
0 8 4 7 2 8
7 8 3 1 8 4
1 2 6 5 4 9
1 1 3 0 8 2
6 3 0 2 4 5
2 0 8 8 0 0
6 8 5 2 7 7
7 5 4 3 7 6
2 7 1 0 1 5

output:

99 199 299 399 499 599 699 799 899 909 919 929 939 949 959 969 979 989 990 991 992 993 994 995 996 997 998 999 1099 1199 1299 1399 1499 1599 1699 1799 1899 1909 1919 1929 1939 1949 1959 1969 1979 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2099 2199 2299 2399 2499 2599 2699 2799 2899 2909...

result:

ok single line: '99 199 299 399 499 599 699 799...799 134899 134909 134919 134929'

Test #13:

score: -100
Time Limit Exceeded

input:

20 10000
5 9 4 8 3 3
1 1 9 2 8 9
6 3 3 0 2 1
2 6 0 3 6 4
3 6 4 2 9 4
8 6 7 3 7 3
3 6 2 0 5 9
5 3 3 5 8 9
1 4 4 5 8 0
1 3 1 4 7 8
6 9 9 8 3 3
1 7 2 8 9 3
0 2 2 8 5 9
9 0 1 2 2 5
5 0 9 1 6 9
0 8 7 7 3 2
7 7 2 7 3 3
3 6 6 6 0 0
7 5 3 5 5 9
9 2 0 0 8 0

output:


result: