Submission #705752

# Submission time Handle Problem Language Result Execution time Memory
705752 2023-03-05T06:23:54 Z myrcella Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
15 / 100
126 ms 163620 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn = 444;

int n;
int a[maxn];
int cnt[3];
ll f[maxn][maxn][maxn][3];
int pos[3][maxn];

int main() {
//	freopen("input.txt","r",stdin);	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	string s;
	cin>>s;
	rep(i,0,n) {
		if (s[i]=='R') cnt[0]++,a[i]=0,pos[0][cnt[0]]=i;
		else if (s[i]=='G') cnt[1]++,a[i]=1,pos[1][cnt[1]]=i;
		else cnt[2]++,a[i]=2,pos[2][cnt[2]]=i;
	}
  	rep(_,1,n+1)
		rep(i,0,cnt[0]+1)
			rep(j,0,cnt[1]+1) {
				int k = _-i-j;
				if (k<0) break;
				if (k>cnt[2]) continue;
      			rep(kk,0,3) f[i][j][k][kk]=1e17;
    		}
	rep(_,0,n)
		rep(i,0,cnt[0]+1)
			rep(j,0,cnt[1]+1) {
				int k = _-i-j;
				if (k<0) break;
				if (k>cnt[2]) continue;
				if (i+1<=cnt[0]) f[i+1][j][k][0] = min(f[i+1][j][k][0],min(f[i][j][k][1],f[i][j][k][2])+abs(_-pos[0][i+1]));
				if (j+1<=cnt[1]) f[i][j+1][k][1] = min(f[i][j+1][k][1],min(f[i][j][k][0],f[i][j][k][2])+abs(_-pos[1][j+1]));
				if (k+1<=cnt[2]) f[i][j][k+1][2] = min(f[i][j][k+1][2],min(f[i][j][k][0],f[i][j][k][1])+abs(_-pos[2][k+1]));
			}
  	
	ll ans = min(f[cnt[0]][cnt[1]][cnt[2]][0],min(f[cnt[0]][cnt[1]][cnt[2]][1],f[cnt[0]][cnt[1]][cnt[2]][2]));
  	if (ans==1e17) cout<<-1;
  	else assert(ans%2==0),cout<<ans/2;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Incorrect 0 ms 468 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Incorrect 0 ms 468 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 95 ms 163592 KB Output is correct
3 Correct 126 ms 162636 KB Output is correct
4 Correct 88 ms 163524 KB Output is correct
5 Correct 86 ms 163532 KB Output is correct
6 Correct 82 ms 163620 KB Output is correct
7 Correct 81 ms 162688 KB Output is correct
8 Correct 97 ms 162608 KB Output is correct
9 Correct 79 ms 161920 KB Output is correct
10 Correct 80 ms 163524 KB Output is correct
11 Correct 81 ms 163508 KB Output is correct
12 Correct 21 ms 44224 KB Output is correct
13 Correct 42 ms 77488 KB Output is correct
14 Correct 56 ms 111648 KB Output is correct
15 Correct 88 ms 163404 KB Output is correct
16 Correct 96 ms 163404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 0 ms 596 KB Output is correct
10 Correct 0 ms 596 KB Output is correct
11 Incorrect 0 ms 468 KB Output isn't correct
12 Halted 0 ms 0 KB -