CodeJam Qualification Round 2022

Posted nike0good

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeJam Qualification Round 2022相关的知识,希望对你有一定的参考价值。

Punched Cards (11pts)

Attempts

1

Penalties

0

Penalty Time

25:02:57

Points

done
Practice Submissions
You have not attempted this problem.
Last updated: Apr 3 2022, 12:13

PROBLEM
ANALYSIS
Problem
A secret team of programmers is plotting to disrupt the programming language landscape and bring punched cards back by introducing a new language called Punched Card Python that lets people code in Python using punched cards! Like good disrupters, they are going to launch a viral campaign to promote their new language before even having the design for a prototype. For the campaign, they want to draw punched cards of different sizes in ASCII art.

Example Punched Card.

The ASCII art of a punched card they want to draw is similar to an R×C matrix without the top-left cell. That means, it has (R⋅C)−1 cells in total. Each cell is drawn in ASCII art as a period (.) surrounded by dashes (-) above and below, pipes (|) to the left and right, and plus signs (+) for each corner. Adjacent cells share the common characters in the border. Periods (.) are used to align the cells in the top row.

For example, the following is a punched card with R=3 rows and C=4 columns:

…±±±+
…|.|.|.|
±±±±+
|.|.|.|.|
±±±±+
|.|.|.|.|
±±±±+
There are more examples with other sizes in the samples below. Given the integers R and C describing the size of a punched card, print the ASCII art drawing of it as described above.

Input
The first line of the input gives the number of test cases, T. T lines follow, each describing a different test case with two integers R and C: the number of rows and columns of the punched card that must be drawn.

Output
For each test case, output one line containing Case #x:, where x is the test case number (starting from 1). Then, output (2⋅R)+1 additional lines with the ASCII art drawing of a punched card with R rows and C columns.

Limits
Time limit: 5 seconds.
Memory limit: 1 GB.
Test Set 1 (Visible Verdict)
1≤T≤81.
2≤R≤10.
2≤C≤10.
Sample
Sample Input
save_alt
content_copy
3
3 4
2 2
2 3
Sample Output
save_alt
content_copy
Case #1:
…±±±+
…|.|.|.|
±±±±+
|.|.|.|.|
±±±±+
|.|.|.|.|
±±±±+
Case #2:
…±+
…|.|
±±+
|.|.|
±±+
Case #3:
…±±+
…|.|.|
±±±+
|.|.|.|
±±±+
Sample Case #1 is the one described in the problem statement. Sample Cases #2 and #3 are additional examples. Notice that the output for each case contains exactly R⋅C+3 periods.

画图题

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n)  \\
						For(j,m-1) cout<<a[i][j]<<' ';\\
						cout<<a[i][m]<<endl; \\
						 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
inline int read()

	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) if (ch=='-') f=-1; ch=getchar();
	while(isdigit(ch))  x=x*10+ch-'0'; ch=getchar();
	return x*f;
 
int main()

//	freopen("A.in","r",stdin);
	int T=read();
	For(kcase,T)
		printf("Case #%d:\\n",kcase);
		int n=read(),m=read();
		cout<<"..";
		For(i,m-1) cout<<"+-";
		cout<<"+\\n";
		For(i,n) 
			putchar(i==1?'.':'|');
			For(i,m) cout<<".|";
			cout<<endl;
			putchar('+');
			For(i,m) cout<<"-+";
			cout<<endl;
		
		
	
	return 0;

3D Printing (13pts)

Attempts

2

Penalties

0

Penalty Time

25:21:25

Points

done
Practice Submissions
You have not attempted this problem.
Last updated: Apr 3 2022, 12:14

PROBLEM
ANALYSIS
Problem
You are part of the executive committee of the Database Design Day festivities. You are in charge of promotions and want to print three D’s to create a logo of the contest. You can choose any color you want to print them, but all three have to be printed in the same color.

Illustration of Sample #1.

You were given three printers and will use each one to print one of the D’s. All printers use ink from 4 individual cartridges of different colors (cyan, magenta, yellow, and black) to form any color. For these printers, a color is uniquely defined by 4 non-negative integers c, m, y, and k, which indicate the number of ink units of cyan, magenta, yellow, and black ink (respectively) needed to make the color.

The total amount of ink needed to print a single D is exactly 106 units. For example, printing a D in pure yellow would use 106 units of yellow ink and 0 from all others. Printing a D in the Code Jam red uses 0 units of cyan ink, 500000 units of magenta ink, 450000 units of yellow ink, and 50000 units of black ink.

To print a color, a printer must have at least the required amount of ink for each of its 4 color cartridges. Given the number of units of ink each printer has in each cartridge, output any color, defined as 4 non-negative integers that add up to 106, such that all three printers have enough ink to print it.

Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of 3 lines. The i-th line of a test case contains 4 integers Ci, Mi, Yi, and Ki, representing the number of ink units in the i-th printer’s cartridge for the colors cyan, magenta, yellow, and black, respectively.

Output
For each test case, output one line containing Case #x: r, where x is the test case number (starting from 1) and r is IMPOSSIBLE if there is no color that can be printed by all 3 printers. Otherwise, r must be equal to “c m y k” where c, m, y, and k are non-negative integers that add up to 106 and c≤Ci, m≤Mi, y≤Yi, and k≤Ki, for all i.

If there are multiple solutions, you may output any one of them. (See “What if a test case has multiple correct solutions?” in the Competing section of the FAQ.) This information about multiple solutions will not be explicitly stated in the remainder of the 2022 contest.

Limits
Time limit: 5 seconds.
Memory limit: 1 GB.
Test Set 1 (Visible Verdict)
1≤T≤100.
0≤Ci≤106, for all i.
0≤Mi≤106, for all i.
0≤Yi≤106, for all i.
0≤Ki≤106, for all i.
Sample
Sample Input
save_alt
content_copy
3
300000 200000 300000 500000
300000 200000 500000 300000
300000 500000 300000 200000
1000000 1000000 0 0
0 1000000 1000000 1000000
999999 999999 999999 999999
768763 148041 178147 984173
699508 515362 534729 714381
949704 625054 946212 951187
Sample Output
save_alt
content_copy
Case #1: 300000 200000 300000 200000
Case #2: IMPOSSIBLE
Case #3: 400001 100002 100003 399994
Sample Case #1 is the image provided above. The proposed color is using up all of the ink in the cyan, magenta, and yellow cartridges of the first printer and all of the ink in the black cartridge of the last printer. This means that no additional unit of ink could be used from any of the 4 ink colors, so the given sample output is the only possible output for this case.

In Sample Case #2, magenta is the only color that both the first and second printers have, so our only chance would be to use 106 units of magenta. Unfortunately, the third printer does not have quite enough, making this case impossible.

In Sample Case #3, other correct outputs are: “400000 100000 100000 400000”, “300000 0 0 700000”, and “350000 140000 160000 350000”, among lots of others. Notice that “300000 140000 160000 700000” would not be a valid answer because, even though there is enough ink in all printers to do that, the total number of ink units must be exactly 106.

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n)  \\
						For(j,m-1) cout<<a[i][j]<<' ';\\
						cout<<a[i][m]<<endl; \\
						 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
inline int read()

	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) if (ch=='-') f=-1; ch=getchar();
	while(isdigit(ch))  x=x*10+ch-'0'; ch=getchar();
	return x*f;
 
int main()

//	freopen("A.in","r",stdin);
	int T=read();
	For(kcase,T)
		int c[4];
		Rep(i,4) cin>>c[i];
		For(i,2) Rep(i,4) c[i]=min(c[i],read());
		printf("Case #%d:",kcase);
		if (c[0]+c[1]+c[2]+c[3]<ll(1e6)) puts(" IMPOSSIBLE");
		else 
			int r = 1e6;
			Rep(i,4) 
				int p=min(r,c[i]);
				r-=p;cout<<' '<<p;
			
			cout<<endl;
		
	
	return 0;



C d1000000 (9pts, 11pts)

Attempts

1

Penalties

0

Penalty Time

25:26:46

Points

done
Points

done
Practice Submissions
You have not attempted this problem.
Last updated: Apr 3 2022, 12:15

PROBLEM
ANALYSIS
Problem
While the most typical type of dice have 6 sides, each of which shows a different integer 1 through 6, there are many games that use other types. In particular, a dk is a die with k sides, each of which shows a different integer 1 through k. A d6 is a typical die, a d4 has four sides, and a d1000000 has one million sides.

Dice from sample case 1

In this problem, we start with a collection of N dice. The i-th die is a dSi, that is, it has Si sides showing integers 1 through Si. A straight of length ℓ starting at x is the list of integers x,x+1,…,x+(ℓ−1). We want to choose some of the dice (possibly all) and pick one number from each to form a straight. What is the longest straight we can form in this way?

Input
The first line of the input gives the number of test cases, T. T test cases follow. Each test case is described in two lines. The first line of a test case contains a single integer N, the number of dice in the game. The second line contains N integers S1,S2,…,SN, each representing the number of sides of a different die.

Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum number of input dice that can be put in a straight.

Limits
Memory limit: 1 GB.
1≤T≤100.
Test Set 1 (Visible Verdict)
Time limit: 5 seconds.
1≤N≤10.
4≤Si≤20, for all i.
Test Set 2 (Visible Verdict)
Time limit: 15 seconds.
1≤N≤105.
4≤Si≤106, for all i.
Sample
Sample Input
save_alt
content_copy
4
4
6 10 12 8
6
5 4 5 4 4 4
10
10 10 7 6 7 4 4 5 7 4
1
10
Sample Output
save_alt
content_copy
Case #1: 4
Case #2: 5
Case #3: 9
Case #4: 1
In Sample Case #1, there are multiple ways to form a straight using all 4 dice. One possible way is shown in the image above.

In Sample Case #2, since none of the dice can show an integer greater than 5, there is no way to have a straight with more than 5 dice. There are multiple ways to form a straight with exactly 5 dice. For example, pick the integers 4 and 5 for both d5⁠’s and then integers 1,2, and 3 for three of the d4⁠’s to form 1,2,3,4,5.

In Sample Case #3, it is possible to form the straight 1,2,3,4,5,6,7,8,9 by discarding one d4 and using the d4⁠’s, d5, and d6 to get 1 through 4; the d7⁠’s to get 5 through 7; and the d10⁠’s to get 8 and 9. There is no way to form a straight of length 10, so this is the best that can be done.

In Sample Case #4, we can only form a straight of length 1, but we can do so by picking any integer for the d10 we are given.

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD<

以上是关于CodeJam Qualification Round 2022的主要内容,如果未能解决你的问题,请参考以下文章

CodeJam Qualification Round 2022

Codejam Qualification Round 2019

CodeJam 最小标量产品问题

Google CodeJam浴室档位2017年资格赛圆形大数据集错误

codeforces 868C Qualification Rounds

Codeforces 868C Qualification Rounds - 位运算