QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755326#9558. The Devilucup-team5657#WA 1ms3852kbC++203.2kb2024-11-16 17:04:052024-11-16 17:04:05

Judging History

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

  • [2024-11-16 17:04:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3852kb
  • [2024-11-16 17:04:05]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
#define _rep(i_,a_,b_) for(int i_ = (a_); i_ <= (b_); ++i_)
#define mid ((L+R) >> 1)
#define multiCase() int testCnt = in(); _rep(curCase,1,testCnt)
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
using ll = long long;
using pii = pair<int,int>;

int in(void) { int x; cin >> x; return x; } ll inl(void) { ll x; scanf("%lld", &x); return x; }
void out(int x) { printf("%d ", x); } void outln(int x) { printf("%d\n", x); }
void out(ll x) { printf("%lld ", x); } void outln(ll x) { printf("%lld\n", x); }
template<typename T> void chkmax(T &a, const T &b) { a = max(a, b); } 
template<typename T> void chkmin(T &a, const T &b) { a = min(a, b); } 
const int kN = 150;
mt19937 umi(830);
vector<string> a[kN];
vector<int> ord[kN];
int pt[kN], per[kN];

vector<string> ans; int anssum = numeric_limits<int>::max();
void update(const vector<string> &cur) {
	int sum = 0; for(auto &x : cur) sum += x.length();
	if(sum < anssum) ans = cur, anssum = sum;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n = in(); cin.get();
	_rep(i,1,n) {
		pt[i] = i;
		string s, t; getline(cin, s);
		istringstream ss(s);
		while(ss >> t) a[i].emplace_back(t);
	}
	_rep(i,1,n) {
		assert(a[i].size() > 0);
		_rep(j,0,a[i].size() - 1) ord[i].emplace_back(j);
	}
	_rep(T,1,100) {
		shuffle(pt + 1, pt + 1 + n, umi);
		unordered_set<string> s;
		vector<string> tmp(n);
		bool nosol = 0;
		_rep(_,1,n) { int i = pt[_];
			_rep(j,0,a[i].size() - 1) per[j] = 1;
			shuffle(ord[i].begin(), ord[i].end(), umi);
			auto Query = [&]() {
				string cur;
				_rep(j,0,a[i].size() - 1) cur += a[i][j].substr(0, per[j]);
				return s.count(cur);
			};
			while(Query()) {
				bool fnd = 0;
				for(auto &id : ord[i]) if(per[id] < a[i][id].length()) {
					++per[id];
					if(!Query()) { fnd = 1; break; }
				}
				if(fnd) continue;
				for(auto &id : ord[i]) if(per[id] < a[i][id].length()) { ++per[id], fnd = 1; break; }
				if(fnd) continue; else { nosol = 1; break; }
			}
			if(nosol) break;
			string cur; 
			_rep(j,0,a[i].size() - 1) cur += a[i][j].substr(0, per[j]);
			tmp[i - 1] = cur, s.insert(cur);
		}
		if(!nosol) update(tmp);
	}
	_rep(T,1,100) {
		shuffle(pt + 1, pt + 1 + n, umi);
		unordered_set<string> s;
		vector<string> tmp(n);
		bool nosol = 0;
		_rep(_,1,n) { int i = pt[_]; 
			_rep(j,0,a[i].size() - 1) per[j] = 1;
			shuffle(ord[i].begin(), ord[i].end(), umi);
			auto Query = [&]() {
				string cur;
				_rep(j,0,a[i].size() - 1) cur += a[i][j].substr(0, per[j]);
				return s.count(cur);
			};
			while(Query()) {
				bool fnd = 0;
				for(auto &id : ord[i]) if(per[id] < a[i][id].length()) { ++per[id], fnd = 1; break; }
				if(!fnd) { nosol = 1; break; }
			}
			if(nosol) break;
			string cur; 
			_rep(j,0,a[i].size() - 1) cur += a[i][j].substr(0, per[j]);
			tmp[i - 1] = cur, s.insert(cur);
		}
		if(!nosol) update(tmp);
	}
	if(anssum == numeric_limits<int>::max()) puts("no solution");
	else for(auto &s : ans) cout << s << endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
automated teller machine
active teller machine
active trouble maker
always telling misinformation
American Teller Machinery

output:

atma
atm
atrm
altm
ATM

result:

ok len=18

Test #2:

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

input:

5
Forest Conservation Committee Forum
Fuming Corruption Collusion Federation
Fulsome Cash Concealment Foundation
Funky Crony Capitalism Facilitator
Funny Cocky Cocky Funny

output:

FCCFo
FCCF
FCaCF
FCCaF
FuCCF

result:

ok len=24

Test #3:

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

input:

3
A AA
AA A
A A A

output:

no solution

result:

ok len=-1

Test #4:

score: 0
Accepted
time: 1ms
memory: 3596kb

input:

2
QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnmertyuiop
Q W E R T Y U I O P A S D F G H J K L Z X C V B N M q w e r t y u i o p a s d f g h j k l z x c v b n m j k l z x c v b n m

output:

Q
QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnmjklzxcvbnm

result:

ok len=63

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 3824kb

input:

10
aaa aaa aaa aaa aaa aaa
aab aaa aaa aaa aaa aaa
aaa aab aaa aaa aaa aaa
aab aab aaa aaa aaa aaa
a a a a a a
ab ab a a a a a a
ab ab b a a a a a a
aw a a a a a
az az a a a a
az a a a a a

output:

aaaaaaaaa
aabaaaaa
aaabaaaa
aaaaaaa
aaaaaa
aaaaaaaa
aabaaaaaa
awaaaaa
azazaaaa
azaaaaa

result:

wrong answer len=77 > ans=76