답안 #944112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944112 2024-03-12T08:38:30 Z Nika533 Paint By Numbers (IOI16_paint) C++14
32 / 100
1 ms 608 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#include "paint.h"
#define pb push_back
#define MOD 1000000007
#define flush fflush(stdout)
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pii pair<int,int>
using namespace std;
const int N=105,K=105;
bool dpPref[N][K],dpSuf[N][K];
int lastBlackPref[N],lastBlackSuf[N];
string solve_puzzle(string s, vector<int> c) {
   int n=s.size(); int k=c.size();
   // build lastBlackPref;
   if (s[0]=='X') lastBlackPref[0]=0;
   else lastBlackPref[0]=-1e9;
   for (int i=1; i<n; i++) {
   	lastBlackPref[i]=lastBlackPref[i-1];
   	if (s[i]=='X') lastBlackPref[i]=i;
	}
	// build lastBlackSuf;
   if (s[n-1]=='X') lastBlackSuf[n-1]=n-1;
   else lastBlackSuf[n-1]=1e9;
   for (int i=n-2; i>=0; i--) {
   	lastBlackSuf[i]=lastBlackSuf[i+1];
   	if (s[i]=='X') lastBlackSuf[i]=i;
	}
   // build dpPref
	int firstBlack=lastBlackSuf[0];
	int lastWhite=-1e9;
	for (int i=c[0]-1; i<=min(n-1,firstBlack+c[0]-1); i++) {
		if (s[i]=='_') lastWhite=i;
   	if (i-c[0]+1>lastWhite) dpPref[i][0]=1; 
	}
   for (int ind=1; ind<k; ind++) {
   	lastWhite=-1e9;
   	for (int i=0; i<n; i++) {
   		if (s[i]=='_') lastWhite=i;
   		if (i-c[ind]+1<=lastWhite) continue;
   		if ((i-c[ind])-1<0) continue;
   		if (s[i-c[ind]]=='X') continue;
   		for (int j=max(0,lastBlackPref[(i-c[ind])-1]); j<=(i-c[ind])-1; j++) {
   			if (dpPref[j][ind-1]==1) dpPref[i][ind]=1;
			}
		}
	}
	// build dpSuf
	int lastBlack=lastBlackPref[n-1];
	lastWhite=1e9;
	for (int i=n-c[k-1]; i>=max(0,lastBlack-c[k-1]+1); i--) {
		if (s[i]=='_') lastWhite=i;
		if (i+c[k-1]-1<lastWhite) dpSuf[i][k-1]=1;
	}
	for (int ind=k-2; ind>=0; ind--) {
		lastWhite=1e9;
		for (int i=n-1; i>=0; i--) {
			if (s[i]=='_') lastWhite=i;
			if (i+c[ind]-1>=lastWhite) continue;
			if ((i+c[ind])+1>n-1) continue;
			if (s[(i+c[ind])]=='X') continue;
			for (int j=min(n-1,lastBlackSuf[(i+c[ind])+1]); j>=(i+c[ind])+1; j--) {
				if (dpSuf[j][ind+1]==1) dpSuf[i][ind]=1;
			}
		}
	}
	// build answer
	string ans=s;
	for (int i=0; i<n; i++) {
		if (s[i]!='.') continue;
		bool canBeWhite=0,canBeBlack=0;
		// can be '_'
		for (int j=i+1; j<=min(n-1,lastBlackSuf[i+1]); j++) {
			if (dpSuf[j][0]==1 && lastBlackPref[i]<0) canBeWhite=1;
		}
		for (int ind=0; ind<k-1; ind++) {
			bool B1=0,B2=0;
			for (int j=i-1; j>=max(0,lastBlackPref[i-1]); j--) {
				if (dpPref[j][ind]==1) B1=1;
			}
			for (int j=i+1; j<=min(n-1,lastBlackSuf[i+1]); j++) {
				if (dpSuf[j][ind+1]==1) B2=1;
			}
			if (B1 && B2) canBeWhite=1;
		}
		for (int j=i-1; j>=max(0,lastBlackPref[i-1]); j--) {
			if (dpPref[j][k-1]==1 && lastBlackSuf[i]>n-1) canBeWhite=1;
		}
		// can be 'X'
		int lb=-1,rb=n;
		for (int j=i; j>=0; j--) {
			if (s[j]=='_') {
				lb=j; break;
			}
		}
		for (int j=i; j<n; j++) {
			if (s[j]=='_') {
				rb=j; break;
			}
		}
		for (int ind=0; ind<k; ind++) {
			for (int o=0; o<c[ind]; o++) {
				if ((i-o)<=lb || rb<=(i+c[ind]-o-1)) continue;
				int l=(i-o),r=(i+c[ind]-o-1);
				if (dpPref[r][ind]==1 && dpSuf[l][ind]==1) canBeBlack=1;
			}
		}
		if (canBeBlack==1 && canBeWhite==1) ans[i]='?';
		else if (canBeBlack==1) ans[i]='X';
		else ans[i]='_';
	}
	return ans;
}

Compilation message

paint.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
8 Correct 1 ms 348 KB n = 20, m = 5
9 Correct 0 ms 348 KB n = 18, m = 3
10 Correct 0 ms 600 KB n = 17, m = 2
11 Correct 1 ms 600 KB n = 20, m = 2
12 Correct 0 ms 348 KB n = 17, m = 4
13 Correct 0 ms 344 KB n = 17, m = 6
14 Correct 1 ms 608 KB n = 17, m = 1
15 Correct 1 ms 600 KB n = 17, m = 4
16 Correct 1 ms 348 KB n = 13, m = 3
17 Correct 0 ms 348 KB n = 18, m = 4
18 Correct 0 ms 348 KB n = 20, m = 10
19 Correct 0 ms 348 KB n = 19, m = 10
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
8 Correct 1 ms 348 KB n = 20, m = 5
9 Correct 0 ms 348 KB n = 18, m = 3
10 Correct 0 ms 600 KB n = 17, m = 2
11 Correct 1 ms 600 KB n = 20, m = 2
12 Correct 0 ms 348 KB n = 17, m = 4
13 Correct 0 ms 344 KB n = 17, m = 6
14 Correct 1 ms 608 KB n = 17, m = 1
15 Correct 1 ms 600 KB n = 17, m = 4
16 Correct 1 ms 348 KB n = 13, m = 3
17 Correct 0 ms 348 KB n = 18, m = 4
18 Correct 0 ms 348 KB n = 20, m = 10
19 Correct 0 ms 348 KB n = 19, m = 10
20 Correct 1 ms 348 KB n = 100, m = 5
21 Correct 1 ms 348 KB n = 90, m = 3
22 Correct 1 ms 348 KB n = 86, m = 2
23 Correct 0 ms 348 KB n = 81, m = 4
24 Correct 1 ms 348 KB n = 89, m = 10
25 Correct 1 ms 348 KB n = 81, m = 23
26 Correct 1 ms 348 KB n = 86, m = 8
27 Correct 1 ms 348 KB n = 53, m = 22
28 Correct 1 ms 348 KB n = 89, m = 35
29 Correct 1 ms 348 KB n = 63, m = 25
30 Correct 1 ms 348 KB n = 100, m = 50
31 Correct 1 ms 348 KB n = 99, m = 50
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
8 Correct 1 ms 348 KB n = 20, m = 5
9 Correct 0 ms 348 KB n = 18, m = 3
10 Correct 0 ms 600 KB n = 17, m = 2
11 Correct 1 ms 600 KB n = 20, m = 2
12 Correct 0 ms 348 KB n = 17, m = 4
13 Correct 0 ms 344 KB n = 17, m = 6
14 Correct 1 ms 608 KB n = 17, m = 1
15 Correct 1 ms 600 KB n = 17, m = 4
16 Correct 1 ms 348 KB n = 13, m = 3
17 Correct 0 ms 348 KB n = 18, m = 4
18 Correct 0 ms 348 KB n = 20, m = 10
19 Correct 0 ms 348 KB n = 19, m = 10
20 Correct 1 ms 348 KB n = 100, m = 5
21 Correct 1 ms 348 KB n = 90, m = 3
22 Correct 1 ms 348 KB n = 86, m = 2
23 Correct 0 ms 348 KB n = 81, m = 4
24 Correct 1 ms 348 KB n = 89, m = 10
25 Correct 1 ms 348 KB n = 81, m = 23
26 Correct 1 ms 348 KB n = 86, m = 8
27 Correct 1 ms 348 KB n = 53, m = 22
28 Correct 1 ms 348 KB n = 89, m = 35
29 Correct 1 ms 348 KB n = 63, m = 25
30 Correct 1 ms 348 KB n = 100, m = 50
31 Correct 1 ms 348 KB n = 99, m = 50
32 Correct 1 ms 348 KB n = 13, m = 4
33 Correct 0 ms 436 KB n = 86, m = 2
34 Correct 1 ms 348 KB n = 88, m = 2
35 Correct 0 ms 348 KB n = 86, m = 2
36 Incorrect 1 ms 348 KB char #8 differ - expected: 'X', found: '?'
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
8 Correct 1 ms 348 KB n = 20, m = 5
9 Correct 0 ms 348 KB n = 18, m = 3
10 Correct 0 ms 600 KB n = 17, m = 2
11 Correct 1 ms 600 KB n = 20, m = 2
12 Correct 0 ms 348 KB n = 17, m = 4
13 Correct 0 ms 344 KB n = 17, m = 6
14 Correct 1 ms 608 KB n = 17, m = 1
15 Correct 1 ms 600 KB n = 17, m = 4
16 Correct 1 ms 348 KB n = 13, m = 3
17 Correct 0 ms 348 KB n = 18, m = 4
18 Correct 0 ms 348 KB n = 20, m = 10
19 Correct 0 ms 348 KB n = 19, m = 10
20 Correct 1 ms 348 KB n = 100, m = 5
21 Correct 1 ms 348 KB n = 90, m = 3
22 Correct 1 ms 348 KB n = 86, m = 2
23 Correct 0 ms 348 KB n = 81, m = 4
24 Correct 1 ms 348 KB n = 89, m = 10
25 Correct 1 ms 348 KB n = 81, m = 23
26 Correct 1 ms 348 KB n = 86, m = 8
27 Correct 1 ms 348 KB n = 53, m = 22
28 Correct 1 ms 348 KB n = 89, m = 35
29 Correct 1 ms 348 KB n = 63, m = 25
30 Correct 1 ms 348 KB n = 100, m = 50
31 Correct 1 ms 348 KB n = 99, m = 50
32 Correct 1 ms 348 KB n = 13, m = 4
33 Correct 0 ms 436 KB n = 86, m = 2
34 Correct 1 ms 348 KB n = 88, m = 2
35 Correct 0 ms 348 KB n = 86, m = 2
36 Incorrect 1 ms 348 KB char #8 differ - expected: 'X', found: '?'
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
8 Correct 1 ms 348 KB n = 20, m = 5
9 Correct 0 ms 348 KB n = 18, m = 3
10 Correct 0 ms 600 KB n = 17, m = 2
11 Correct 1 ms 600 KB n = 20, m = 2
12 Correct 0 ms 348 KB n = 17, m = 4
13 Correct 0 ms 344 KB n = 17, m = 6
14 Correct 1 ms 608 KB n = 17, m = 1
15 Correct 1 ms 600 KB n = 17, m = 4
16 Correct 1 ms 348 KB n = 13, m = 3
17 Correct 0 ms 348 KB n = 18, m = 4
18 Correct 0 ms 348 KB n = 20, m = 10
19 Correct 0 ms 348 KB n = 19, m = 10
20 Correct 1 ms 348 KB n = 100, m = 5
21 Correct 1 ms 348 KB n = 90, m = 3
22 Correct 1 ms 348 KB n = 86, m = 2
23 Correct 0 ms 348 KB n = 81, m = 4
24 Correct 1 ms 348 KB n = 89, m = 10
25 Correct 1 ms 348 KB n = 81, m = 23
26 Correct 1 ms 348 KB n = 86, m = 8
27 Correct 1 ms 348 KB n = 53, m = 22
28 Correct 1 ms 348 KB n = 89, m = 35
29 Correct 1 ms 348 KB n = 63, m = 25
30 Correct 1 ms 348 KB n = 100, m = 50
31 Correct 1 ms 348 KB n = 99, m = 50
32 Correct 1 ms 348 KB n = 13, m = 4
33 Correct 0 ms 436 KB n = 86, m = 2
34 Correct 1 ms 348 KB n = 88, m = 2
35 Correct 0 ms 348 KB n = 86, m = 2
36 Incorrect 1 ms 348 KB char #8 differ - expected: 'X', found: '?'
37 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB n = 13, m = 1
2 Correct 0 ms 348 KB n = 18, m = 1
3 Correct 1 ms 348 KB n = 17, m = 1
4 Correct 1 ms 348 KB n = 1, m = 1
5 Correct 0 ms 348 KB n = 20, m = 1
6 Correct 0 ms 348 KB n = 20, m = 1
7 Correct 1 ms 348 KB n = 20, m = 1
8 Correct 1 ms 348 KB n = 20, m = 5
9 Correct 0 ms 348 KB n = 18, m = 3
10 Correct 0 ms 600 KB n = 17, m = 2
11 Correct 1 ms 600 KB n = 20, m = 2
12 Correct 0 ms 348 KB n = 17, m = 4
13 Correct 0 ms 344 KB n = 17, m = 6
14 Correct 1 ms 608 KB n = 17, m = 1
15 Correct 1 ms 600 KB n = 17, m = 4
16 Correct 1 ms 348 KB n = 13, m = 3
17 Correct 0 ms 348 KB n = 18, m = 4
18 Correct 0 ms 348 KB n = 20, m = 10
19 Correct 0 ms 348 KB n = 19, m = 10
20 Correct 1 ms 348 KB n = 100, m = 5
21 Correct 1 ms 348 KB n = 90, m = 3
22 Correct 1 ms 348 KB n = 86, m = 2
23 Correct 0 ms 348 KB n = 81, m = 4
24 Correct 1 ms 348 KB n = 89, m = 10
25 Correct 1 ms 348 KB n = 81, m = 23
26 Correct 1 ms 348 KB n = 86, m = 8
27 Correct 1 ms 348 KB n = 53, m = 22
28 Correct 1 ms 348 KB n = 89, m = 35
29 Correct 1 ms 348 KB n = 63, m = 25
30 Correct 1 ms 348 KB n = 100, m = 50
31 Correct 1 ms 348 KB n = 99, m = 50
32 Correct 1 ms 348 KB n = 13, m = 4
33 Correct 0 ms 436 KB n = 86, m = 2
34 Correct 1 ms 348 KB n = 88, m = 2
35 Correct 0 ms 348 KB n = 86, m = 2
36 Incorrect 1 ms 348 KB char #8 differ - expected: 'X', found: '?'
37 Halted 0 ms 0 KB -