Codeforces Round #382 (Div. 1), problem: (E) Chess Championship Solution in C/C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 3010
using namespace std;
int n,m,f[N][N];
struct ma{int x,y;}a[N];
bool operator<(ma p,ma q){return p.x>q.x;}
void get(int k)
{
	sort(a+k,a+n+1);
	int w=a[k].x;
	for(int i=n;i>k;i--)
	{
		if(w>1) w-=2,f[a[k].y][a[i].y]=1;
		else if(!w) a[i].x-=2,f[a[i].y][a[k].y]=1;
		else w--,a[i].x--,f[a[k].y][a[i].y]=f[a[i].y][a[k].y]=2;
	}
	a[k].x=0;
}
int main()
{
	cin>>n>>m;
	int x=0,sum=0;
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&a[i].x);
		a[i].y=i;
		x+=2*(n-i);
		sum+=a[i].x;
		if(sum>x) return puts("no"),0;
	}
	for(int i=m+1;i<=n;i++)
	{
		a[i].y=i;
		x+=2*(n-i);
		a[i].x=min(a[i-1].x,x-sum);
		sum+=a[i].x;
	}
	if(sum!=x) return puts("no"),0;
	for(int i=1;i<n;i++) get(i);
	puts("yes");
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i==j) putchar('X');
			else if(!f[i][j]) putchar('L');
			else if(f[i][j]==1) putchar('W');
			else putchar('D');
		}
		puts("");
	}
}

Advertisement

spot_img

Is the Keurig K-Mini...

Keurig K-Mini Long-Term Review: 12 Months of Daily Brewing First-impression...

Can You Make Iced...

How to Brew Refreshing Iced Coffee with the Keurig...

Keurig K-Mini vs Keurig...

Keurig K-Mini vs Keurig K-Slim: Comparing Keurig’s Slimmest Brewers Keurig’s...

Best K-Cup Coffee Pods...

Top Rated K-Cup Coffee Pods for the Keurig K-Mini The...

How to Fix a...

How to Clear Needle Clogs and Fix Slow Flow...

Keurig K-Mini Auto-Off Feature...

Keurig K-Mini Energy Efficiency & Power Consumption Analysis As electricity...

Is the Keurig K-Mini Worth It Long Term? 1-Year Reliability, Durability & Value

Keurig K-Mini Long-Term Review: 12 Months of Daily Brewing First-impression reviews written after three days of testing can tell you how an appliance looks on...

Can You Make Iced Coffee with the Keurig K-Mini? Brew Temperature & Iced Recipes

How to Brew Refreshing Iced Coffee with the Keurig K-Mini During warm summer months, nothing satisfies quite like a tall glass of refreshing iced coffee....

Keurig K-Mini vs Keurig K-Slim: Multi-Cup Reservoir vs Ultra-Compact Brewer

Keurig K-Mini vs Keurig K-Slim: Comparing Keurig’s Slimmest Brewers Keurig’s product catalog features two popular models specifically marketed to space-conscious consumers: the ultra-compact Keurig K-Mini...

Best K-Cup Coffee Pods for Keurig K-Mini: Dark, Medium, Flavored & Decaf Roasts

Top Rated K-Cup Coffee Pods for the Keurig K-Mini The beauty of owning a Keurig K-Mini Single Serve Coffee Maker is universal pod compatibility. Unlike...

How to Fix a Clogged Keurig K-Mini: Exit Needle Cleaning & Troubleshooting Guide

How to Clear Needle Clogs and Fix Slow Flow on the Keurig K-Mini If your Keurig K-Mini suddenly dispenses half a cup of coffee, drips...

Keurig K-Mini Auto-Off Feature and Power Consumption: Energy Efficiency Tested

Keurig K-Mini Energy Efficiency & Power Consumption Analysis As electricity costs rise and consumers increasingly prioritize eco-conscious household appliances, power consumption has become an important...

Keurig K-Mini Dimensions and Cord Storage: Best Compact Coffee Maker for Dorms & RVs

Keurig K-Mini Dimensions & Space-Saving Ergonomics Countertop real estate in modern living spaces has never been tighter. In college dormitories, studio micro-apartments, home office workstations,...

How to Use Reusable K-Cup Coffee Filters with the Keurig K-Mini: Universal Pod Guide

How to Brew Fresh Ground Coffee in Your Keurig K-Mini While pre-packaged K-Cup pods deliver unbeatable morning convenience, they come with two distinct trade-offs: ongoing...

Keurig K-Mini vs Nespresso Vertuo Pop: Compact Coffee Maker Comparison

Keurig K-Mini vs Nespresso Vertuo Pop: The Battle of Compact Brewers Single-serve coffee has evolved into two dominant, competing ecosystems: the versatile, drip-style Keurig K-Cup...