QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755333#9558. The Devilucup-team5657#WA 2ms3892kbC++202.4kb2024-11-16 17:05:252024-11-16 17:05:25

Judging History

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

  • [2024-11-16 17:05:25]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3892kb
  • [2024-11-16 17:05:25]
  • 提交

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,1000) {
		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);
	}
	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: 1ms
memory: 3660kb

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: 2ms
memory: 3532kb

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: 3892kb

input:

3
A AA
AA A
A A A

output:

no solution

result:

ok len=-1

Test #4:

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

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: 2ms
memory: 3660kb

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:

aaaaaaa
aaaaaaaa
aaaaaaaaa
aaaaaaaaaa
aaaaaa
abaaaaaaa
aabaaaaaa
awaaaaa
aazaaaa
azaaaaa

result:

wrong answer len=79 > ans=76