QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#487276#5339. Mixing ColoursPetroTarnavskyiAC ✓9028ms451412kbC++201.9kb2024-07-22 19:35:162024-07-22 19:35:16

Judging History

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

  • [2024-07-22 19:35:16]
  • 评测
  • 测评结果:AC
  • 用时:9028ms
  • 内存:451412kb
  • [2024-07-22 19:35:16]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

map<string, int> id;
map<int, string> rid;
int addStr(string a)
{
	if(!id.count(a))
	{
		id[a] = SZ(id);
		rid[id[a]] = a;
	}
	return id[a];
}

const int INF = 1e9;
const int N = 1 << 9;
const int R = 104;



vector<PII> rules[3 * R];

db dpT[N][N][3 * R];

void solve()
{
	int n;
	cin >> n;
	
	FOR(i, 0, n + 1)
		FOR(j, 0, n + 1)
			fill(dpT[i][j], dpT[i][j] + 3 * R, -INF);
	
	FOR(i, 0, n)
	{
		string s;
		while(cin >> s)
		{
			if(s == "END")
				break;
			
			int col = addStr(s);
			db prob;
			cin >> prob;
			prob = log(prob);
			
			dpT[i][i + 1][col] = prob;
		}
	}
	int sz = SZ(id);
	RFOR(l, n, 0)
	{
		FOR(r, l + 2, n + 1)
		{
			FOR(c, 0, sz)
			{
				FOR(m, l + 1, r)
				{
					db sum = -INF;
					for(auto rule : rules[c])
						sum = max(sum, dpT[l][m][rule.F] + dpT[m][r][rule.S]);
						
					dpT[l][r][c] = max(dpT[l][r][c], sum);
				}				
			}
		}
	}
	int ans = -1;
	FOR(c, 0, sz)
	{
		if(dpT[0][n][c] == -INF)
			continue;
			
		if(ans == -1 || dpT[0][n][c] > dpT[0][n][ans])
			ans = c;
	}
	if(ans == -1)
		cout << "GAMEOVER\n";
	else
		cout << rid[ans] << "\n";
}


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

	int r;	
	cin >> r;
	FOR(i, 0, r)
	{
		string a, b, c;
		cin >> a >> b >> c;
		
		int A = addStr(a);
		int B = addStr(b);
		int C = addStr(c);
		
		rules[C].PB({A, B});
		rules[C].PB({B, A});
	}
	
	int q;
	cin >> q;
	while(q--)
	{
		solve();
	}
	
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 10192kb

input:

7
Blue Yellow Green
Yellow Red Orange
Green Red Yellow
White Red Pink
Pink Black Red
Orange Red Red
Yellow Orange Yellow
3
2
Red 0.7 Orange 0.3 END
Yellow 1.0 END
4
Blue 0.6 Green 0.4 END
Red 0.2 Orange 0.6 Yellow 0.2 END
White 0.9 Yellow 0.1 END
Red 0.5 Black 0.5 END
2
Blue 1.0 END
Orange 1.0 END

output:

Orange
Yellow
GAMEOVER

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 334ms
memory: 139140kb

input:

100
Red Corn Blue
Red Sand Blond
Red Blush Lion
Tan Gray Drab
Tan Kobe Lava
Tan Amber Peru
Tan Blush Ecru
Ube Pink Puce
Ube Camel Aqua
Jet Ceil Onyx
Jet Rose Cyan
Blue Fawn Flax
Blue Peru Rust
Blue Snow Ceil
Blue Camel Ube
Aqua Mint Rose
Aqua Onyx Beige
Aqua Sand Jet
Aqua Snow Beige
Aqua Soap Lion
B...

output:

Lion
Jet
Camel
Iris
GAMEOVER

result:

ok 5 lines

Test #3:

score: 0
Accepted
time: 9028ms
memory: 451412kb

input:

90
Red Soap Azure
Tan Bole Puce
Tan Lava Ecru
Tan Lion Lust
Tan Puce Corn
Ube Buff Onyx
Jet Jade Beige
Jet Lion Amber
Blue Aqua Soap
Blue Soap Drab
Aqua Cyan Jade
Aqua Lava Ceil
Aqua Mint Kobe
Aqua Pink Lion
Aqua Teal Ecru
Aqua Camel Onyx
Bole Bone Blue
Bole Corn Mint
Bole Deer Bone
Bole Pink Kobi
B...

output:

GAMEOVER
Ceil
Ceil
Lion

result:

ok 4 lines