Submission #895105

# Submission time Handle Problem Language Result Execution time Memory
895105 2023-12-29T12:26:20 Z hariaakas646 Growing Vegetable is Fun 3 (JOI19_ho_t3) C++14
0 / 100
500 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t);
#define forr(i, l, r) for(int i=l; i<r; i++)
#define frange(i, l) forr(i, 0, l)
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef long long lli;
typedef vector<vi> vvi;
typedef vector<lli> vll;
typedef vector<bool> vb;
typedef set<int> seti;

void usaco() {
	freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
}

int n;

lli dist(string &st1, string &st2) {
	vi r1, g1, y1, r2, g2, y2;
	lli tot = 0;
	frange(i, n) {
		if(st1[i] == 'R') r1.pb(i);
		if(st1[i] == 'G') g1.pb(i);
		if(st1[i] == 'Y') y1.pb(i);

		if(st2[i] == 'R') r2.pb(i);
		if(st2[i] == 'G') g2.pb(i);
		if(st2[i] == 'Y') y2.pb(i);
	}
	if(r1.size() != r2.size()) return 1e18;
	if(g1.size() != g2.size()) return 1e18;
	if(y1.size() != y2.size()) return 1e18;
	frange(i, r1.size()) tot += abs(r1[i] - r2[i]);
	frange(i, g1.size()) tot += abs(g1[i] - g2[i]);
	frange(i, y1.size()) tot += abs(y1[i] - y2[i]);
	return tot/2;
}

int main() {
	//usaco();
	string str;
	cin >> n >> str;

	// int rc = 0;
	// int gc = 0;

	// frange(i, n) {
	// 	if(str[i] == 'R') rc++;
	// 	else gc++;
	// }

	// if(rc == gc) {
	// 	string str1, str2;
	// 	frange(i, n) {
	// 		if(i % 2) {
	// 			str1 += 'R';
	// 			str2 += 'G';
	// 		}
	// 		else {
	// 			str1 += 'G';
	// 			str2 += 'R';
	// 		}
	// 	}
	// 	printf("%lld", min(dist(str, str1), dist(str, str2)));
	// }
	// else if(rc == gc+1) {
	// 	string str1;
	// 	frange(i, n) {
	// 		if(i % 2==0) str1 += 'R';
	// 		else str1 += 'G';
	// 	}
	// 	printf("%lld", dist(str, str1));
	// }
	// else if(rc == gc-1) {
	// 	string str1;
	// 	frange(i, n) {
	// 		if(i % 2) str1 += 'R';
	// 		else str1 += 'G';
	// 	}
	// 	printf("%lld", dist(str, str1));
	// }
	// else printf("-1");


	lli mi = 1e18;
	int x = 1;
	frange(i, n) x *= 3;
	frange(i, x) {
		string out;
		int v = i;
		frange(j, n) {
			if(v % 3 == 2) out += 'R';
			else if(v % 3 == 1) out += 'G';
			else out += 'Y';
			v /= 3;
		}
		bool done = false;
		forr(i, 1, n) {
			if(out[i] == out[i-1]) done = true;
		}
		if(done) continue;
		mi = min(mi, dist(str, out));
	}
	if(mi < 1e18)
	printf("%lld", mi);
	else printf("-1");

}

Compilation message

joi2019_ho_t3.cpp: In function 'lli dist(std::string&, std::string&)':
joi2019_ho_t3.cpp:7:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forr(i, l, r) for(int i=l; i<r; i++)
      |                                     ^
joi2019_ho_t3.cpp:8:22: note: in expansion of macro 'forr'
    8 | #define frange(i, l) forr(i, 0, l)
      |                      ^~~~
joi2019_ho_t3.cpp:45:2: note: in expansion of macro 'frange'
   45 |  frange(i, r1.size()) tot += abs(r1[i] - r2[i]);
      |  ^~~~~~
joi2019_ho_t3.cpp:7:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forr(i, l, r) for(int i=l; i<r; i++)
      |                                     ^
joi2019_ho_t3.cpp:8:22: note: in expansion of macro 'forr'
    8 | #define frange(i, l) forr(i, 0, l)
      |                      ^~~~
joi2019_ho_t3.cpp:46:2: note: in expansion of macro 'frange'
   46 |  frange(i, g1.size()) tot += abs(g1[i] - g2[i]);
      |  ^~~~~~
joi2019_ho_t3.cpp:7:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 | #define forr(i, l, r) for(int i=l; i<r; i++)
      |                                     ^
joi2019_ho_t3.cpp:8:22: note: in expansion of macro 'forr'
    8 | #define frange(i, l) forr(i, 0, l)
      |                      ^~~~
joi2019_ho_t3.cpp:47:2: note: in expansion of macro 'frange'
   47 |  frange(i, y1.size()) tot += abs(y1[i] - y2[i]);
      |  ^~~~~~
joi2019_ho_t3.cpp: In function 'void usaco()':
joi2019_ho_t3.cpp:25:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  freopen("/media/hariaakash646/785EF1075EF0BF46/CompetitiveProgramming/input.in", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Execution timed out 1090 ms 348 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Execution timed out 1090 ms 348 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1045 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Execution timed out 1090 ms 348 KB Time limit exceeded
6 Halted 0 ms 0 KB -