QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#323968#8230. Submissionsucup-team266#TL 2ms22016kbC++145.6kb2024-02-10 14:43:332024-02-10 14:43:34

Judging History

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

  • [2024-05-20 23:50:57]
  • hack成功,自动添加数据
  • (/hack/623)
  • [2024-05-20 23:48:44]
  • hack成功,自动添加数据
  • (/hack/622)
  • [2024-02-10 14:43:34]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:22016kb
  • [2024-02-10 14:43:33]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef array<int, 3> ai3;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const int Mod = 147744151;
const int inv[5] = {0, 1, (Mod+1) / 2, (Mod+1) / 3};
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 111;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
	pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
	invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
	fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
	invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return (m < 0 || m > n) ? 0 : mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
inline void chmin(ll &a, ll b){ (b<a) ? (a=b) : 0; }

map<string, int> mp;
int cn = 0;
int has0[100100][26], fst0[100100][26], lst0[100100][26], has1[100100][26], cnt[100100], tpen[100100][26], pen[100100], can[100100];
int nhas0[100100][26], nhas1[100100][26], ntpen[100100][26];
int m;

int ord[100100];
int calc(){
	rep(i, cn) ord[i] = i;
	//rep(i, cn) cout << "(" << cnt[i] << " " << pen[i] << ") ";
	//cout << "\n";
	sort(ord, ord + cn, [&](int lh, int rh){
		if(cnt[lh] != cnt[rh])
			return cnt[lh] > cnt[rh];
		else 
			return pen[lh] < pen[rh];
	});
	int lmt = 0;
	while(lmt < cn && cnt[ord[lmt]]) ++lmt;
	lmt = min((lmt+9) / 10, 35);
	rep(i, lmt) can[ord[i]] = 1;
	if(lmt){
		int p = lmt;
		while(cnt[ord[p]] == cnt[ord[p-1]] && pen[ord[p]] == pen[ord[p-1]]) can[ord[p++]] = 1;
	}
	return lmt;
}

void solve(){
	mp.clear(), cn = 0;
	cin >> m;
	rep(i, m){
		memset(has0[i], 0, sizeof(has0[i])), memset(has1[i], 0, sizeof(has1[i])), can[i] = cnt[i] = pen[i] = 0;
		memset(nhas0[i], 0, sizeof(nhas0[i])), memset(nhas1[i], 0, sizeof(nhas1[i]));
	}
	while(m--){
		string c;
		char cp;
		int t;
		string s;
		cin >> c >> cp >> t >> s;
		if(!mp.count(c)) mp[c] = cn++;
		int id = mp[c];
		int p = (int)(cp - 'A'), tp = (s[0] == 'a');
		if(!has1[id][p]){
			if(tp == 1){
				pen[id] += (tpen[id][p] = (t + 20 * has0[id][p]));
				has1[id][p] = 1;
			} else {
				if(!has0[id][p]) fst0[id][p] = t;
				lst0[id][p] = t;
				++has0[id][p];
			}
		} else if(!nhas1[id][p]){
			if(tp == 1){
				ntpen[id][p] = (t + 20 * (has0[id][p] + 1 + nhas0[id][p]));
				nhas1[id][p] = 1;
			} else {
				++nhas0[id][p];
			}
		}
	}

	rep(i, cn) rep(j, 26) cnt[i] += has1[i][j];

	int n = 0;
	rep(i, cn) n += (bool)(cnt[i]);
	int lmt = calc();

	if(!lmt){
		rep(i, cn){
			int has = 0;
			rep(j, 26) has |= has0[i][j];
			can[i] = has;
		}
	} else {
		int lst = ord[lmt-1];

		rep(i, cn) if(!can[i]){
			//cout << "! " << i << "\n";
			int mnp = -1;
			rep(j, 26) if(!has1[i][j] && has0[i][j] && (mnp < 0 || fst0[i][j] < fst0[i][mnp])){
				mnp = j;
			}
			//cout << mnp << "\n";
			if(mnp >= 0){
				if(cnt[i] == cnt[lst]) can[i] = 1;
				else {
					//cout << i << ": " << (!cnt[i] && lmt < 35 && n % 10 == 0) << "\n";
					int nxt = ord[lmt + (!cnt[i] && lmt < 35 && n % 10 == 0) - 1];
					can[i] |= (cnt[i] + 1 > cnt[nxt] || (cnt[i] + 1 == cnt[nxt] && pen[i] + fst0[i][mnp] <= pen[nxt]));
				}
			}
			mnp = -1;
			rep(j, 26) if(has1[i][j] && has0[i][j] && (mnp < 0 || fst0[i][j] - tpen[i][j] < fst0[i][mnp] - tpen[i][mnp])){
				mnp = j;
			}
			if(mnp >= 0){
				can[i] |= (cnt[i] == cnt[lmt-1] && pen[i] + fst0[i][mnp] - tpen[i][mnp] <= pen[lmt-1]);
			}
		}

		if(lmt){
			if(cnt[ord[lmt]] == cnt[ord[lmt-1]] && pen[ord[lmt]] == pen[ord[lmt-1]])
				;
			else {
				bool done = 0;
				rep(i, lmt){
					int u = ord[i];
					rep(j, 26) if(has1[u][j]){
						if(!nhas1[u][j] && (cnt[u] - 1 < cnt[ord[lmt]] || (cnt[u] - 1 == cnt[ord[lmt]] && pen[u] - tpen[u][j] >= pen[ord[lmt]]))){
							--cnt[u], pen[u] -= tpen[u][j];
							calc(); done = 1;
							++cnt[u], pen[u] += tpen[u][j];
						} else if(cnt[u] == cnt[ord[lmt]] && pen[u] - tpen[u][j] + ntpen[u][j] >= pen[ord[lmt]]){
							pen[u] += ntpen[u][j] - tpen[u][j];
							calc(); done = 1;
							pen[u] -= ntpen[u][j] - tpen[u][j];
						}
						if(done) break;
					}
					if(done) break;
				}
				if(done) calc();
			}
		}
		
		rep(i, cn) if(!cnt[i]){
			int mxp = -1;
			rep(j, 26) if(has0[i][j]){
				if(mxp < 0 || lst0[i][j] + 20 * (has0[i][j] - 1) > lst0[i][mxp] + 20 * (has0[i][mxp] - 1))
					mxp = j;
			}
			if(mxp >= 0){
				++cnt[i], pen[i] += lst0[i][mxp] + 20 * (has0[i][mxp] - 1);
				calc();
				break;
			}
		}
	}

	int sum = 0;
	for(auto it : mp) sum += (can[it.second]);
	cout << sum << "\n";
	for(auto it : mp) if(can[it.second]) cout << it.first << " ";
	cout << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int T;
	cin >> T;
	while(T--)
		solve();

	return 0;
}

详细

Test #1:

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

input:

2
5
TSxingxing10 G 0 rejected
TSxingxing10 B 83 accepted
aoliaoligeiliao J 98 accepted
TS1 J 118 accepted
TS1 B 263 accepted
12
AllWayTheNorth A 0 rejected
YaoYaoLingXian Y 10 accepted
XuejunXinyoudui1 X 200 rejected
XuejunXinyoudui1 X 200 accepted
LetItRot L 215 accepted
AllWayTheNorth W 250 accept...

output:

2
TS1 TSxingxing10 
4
AllWayTheNorth ImYourFan LetItRot XuejunXinyoudui1 

result:

ok 2 test cases ok. (2 test cases)

Test #2:

score: 0
Accepted
time: 2ms
memory: 13892kb

input:

2
2
jiangly_fan A 1 accepted
jiangly B 23 accepted
3
conqueror_of_tourist A 1 accepted
conqueror_of_tourist A 2 accepted
tourist B 23 accepted

output:

2
jiangly jiangly_fan 
1
conqueror_of_tourist 

result:

ok 2 test cases ok. (2 test cases)

Test #3:

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

input:

2
13
A A 1 accepted
A X 1 accepted
K K 1 rejected
B B 2 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 accepted
G G 2 accepted
H H 2 accepted
I I 2 accepted
J J 2 accepted
K K 2 rejected
12
A A 1 accepted
A X 1 accepted
B B 2 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 a...

output:

11
A B C D E F G H I J K 
1
A 

result:

ok 2 test cases ok. (2 test cases)

Test #4:

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

input:

2
11
A A 1 accepted
B B 1 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 accepted
G G 2 accepted
H H 2 accepted
I I 2 accepted
J J 2 accepted
K K 2 accepted
12
A A 1 accepted
A X 1 accepted
K K 1 rejected
B B 2 accepted
C C 2 accepted
D D 2 accepted
E E 2 accepted
F F 2 accepted
G G 2 a...

output:

2
A B 
2
A K 

result:

ok 2 test cases ok. (2 test cases)

Test #5:

score: -100
Time Limit Exceeded

input:

100000
1
M3JytWoaEXxkACy_mBAQ R 111 accepted
1
sQ O 151 accepted
1
JinbrcS58gNEE5yTSkT B 140 accepted
1
cklwBY V 243 accepted
1
v_o42YmvEKFwy Q 260 rejected
1
ftQVK8S_um22w K 265 accepted
1
_bQBeFeDpYQhvZcLf9l3 Z 147 accepted
1
KvDcEAIDN A 75 rejected
1
H3MUK6 A 101 rejected
1
gxYo_oCFn2J8aIben U 54...

output:

1
M3JytWoaEXxkACy_mBAQ 
1
sQ 
1
JinbrcS58gNEE5yTSkT 
1
cklwBY 
1
v_o42YmvEKFwy 
1
ftQVK8S_um22w 
1
_bQBeFeDpYQhvZcLf9l3 
1
KvDcEAIDN 
1
H3MUK6 
1
gxYo_oCFn2J8aIben 
1
_isnlUGK0ddI 
1
BERcVjyCp 
1
6In2do_50ylch 
1
f0r3SXc6brMjT 
1
7njYOapSwvogA 
1
x 
1
y1w3KvxylfxwprRBYw 
1
aGedzS 
1
iPo0GDhIF 
1
4Vf...

result: