Submission #311040

# Submission time Handle Problem Language Result Execution time Memory
311040 2020-10-09T07:52:14 Z anakib1 Horses (IOI15_horses) C++17
54 / 100
714 ms 22008 KB
//나는 가상 소녀들에게 큰 호감이 있습니다.

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define sz(a) (int)(a.size())
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define problem "a"

template<typename A, typename B, typename C>
struct triple {
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a) {
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c) {
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c) {
	return min(a, min(b, c));
}
template<typename T, typename D>
D min(T a) {
	return *min_element(all(a));
}
template<typename T, typename D>
D max(T a) {
	return *max_element(all(a));
}
struct custom_hash {
	static uint64_t splitmix64(uint64_t x) {
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};



static char _buffer[1024];
static int _currentChar = 0;
static int _charsNumber = 0;
static FILE* _inputFile, * _outputFile;

static inline int _read() {
	if (_charsNumber < 0) {
		exit(1);
	}
	if (!_charsNumber || _currentChar == _charsNumber) {
		_charsNumber = (int)fread(_buffer, sizeof(_buffer[0]), sizeof(_buffer), _inputFile);
		_currentChar = 0;
	}
	if (_charsNumber <= 0) {
		return -1;
	}
	return _buffer[_currentChar++];
}

static inline int _readInt() {
	int c, x, s;
	c = _read();
	while (c <= 32) c = _read();
	x = 0;
	s = 1;
	if (c == '-') {
		s = -1;
		c = _read();
	}
	while (c > 32) {
		x *= 10;
		x += c - '0';
		c = _read();
	}
	if (s < 0) x = -x;
	return x;
}
int n, st;
vi x, y;
const ll mod = 1e9 + 7;
int pw(int x, int y) {
	if (!y) return 1;
	int v = pw(x, y >> 1);
	v = (v * 1LL * v) % mod;
	if (y & 1) v = (v * 1LL * x) % mod;
	return v;
}
int pr = 1;
int solve1() {
	ld ans = 0;
	int p = st;
	vector<ld> v(n - st);
	v[0] = 0;
	for (int i = st + 1; i < n; i++) v[i - st] = v[i - st - 1] + log2l(x[i]);
	for (int i = st; i < n; i++) if (ans < v[i - st] + log2l(y[i])) { p = i; ans = v[i - st] + log2l(y[i]); }
	ll res = pr;
	//cout << p << '\n';
	for(int i = st; i <= p; i++) res = (res * 1LL  * x[i]) % mod;
	return (res * 1LL * y[p]) %mod;
}
int solve2() {
	int p = 0;
	ld ans = 0;
	vector<ld> v(n);
	rngi(i, n) v[i] = (i ? v[i - 1] : 0LL) + log2l(x[i]);
	//print(v);
	for (int i = 0; i < n; i++)
		if (ans < v[i] + log2l(y[i])) { ans = v[i] + log2l(y[i]), p = i; }
	ll res = 1;
	//cout << p << '\n';
	rngi(i, p + 1) res = (res * 1LL * x[i]) % mod;
	return (res * 1LL * y[p]) % mod;
}
int solve() { if (n <= 1000) return solve2(); return solve1(); }

int init(int N, int X[], int Y[]) {
	n = N; x = y = vi(n);
	st = max(0, n - 34);
	rngi(i, n) x[i] = X[i], y[i] = Y[i];
	for (int i = 0; i < st; i++) pr = (pr * 1LL * x[i]) % mod;
	return solve();
}

int updateX(int pos, int val) {
	if (pos < st) {
		pr = (pr * 1LL * pw(x[pos], mod - 2)) % mod;
		pr = (pr * 1LL * val) % mod;
	}

	x[pos] = val;
	return solve();
}

int updateY(int pos, int val) {
	y[pos] = val;
	return solve();
}


/*int main() {
	_inputFile = fopen("horses.in", "rb");
	_outputFile = fopen("horses.out", "w");

	int N; N = _readInt();

	int* X = (int*)malloc(sizeof(int) * (unsigned int)N);
	int* Y = (int*)malloc(sizeof(int) * (unsigned int)N);

	for (int i = 0; i < N; i++) {
		X[i] = _readInt();
	}

	for (int i = 0; i < N; i++) {
		Y[i] = _readInt();
	}

	fprintf(_outputFile, "%d\n", init(N, X, Y));

	int M; M = _readInt();

	for (int i = 0; i < M; i++) {
		int type; type = _readInt();
		int pos; pos = _readInt();
		int val; val = _readInt();

		if (type == 1) {
			fprintf(_outputFile, "%d\n", updateX(pos, val));
		}
		else if (type == 2) {
			fprintf(_outputFile, "%d\n", updateY(pos, val));
		}
	}

	return 0;
}
*/

Compilation message

horses.cpp: In function 'int pw(int, int)':
horses.cpp:155:20: warning: declaration of 'y' shadows a global declaration [-Wshadow]
  155 | int pw(int x, int y) {
      |                    ^
horses.cpp:153:7: note: shadowed declaration is here
  153 | vi x, y;
      |       ^
horses.cpp:155:20: warning: declaration of 'x' shadows a global declaration [-Wshadow]
  155 | int pw(int x, int y) {
      |                    ^
horses.cpp:153:4: note: shadowed declaration is here
  153 | vi x, y;
      |    ^
horses.cpp:158:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  158 |  v = (v * 1LL * v) % mod;
      |      ~~~~~~~~~~~~~~^~~~~
horses.cpp:159:31: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  159 |  if (y & 1) v = (v * 1LL * x) % mod;
      |                 ~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int solve1()':
horses.cpp:173:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  173 |  return (res * 1LL * y[p]) %mod;
      |         ~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve2()':
horses.cpp:186:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  186 |  return (res * 1LL * y[p]) % mod;
      |         ~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:194:54: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  194 |  for (int i = 0; i < st; i++) pr = (pr * 1LL * x[i]) % mod;
      |                                    ~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:200:41: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  200 |   pr = (pr * 1LL * pw(x[pos], mod - 2)) % mod;
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:201:25: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
  201 |   pr = (pr * 1LL * val) % mod;
      |        ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: At global scope:
horses.cpp:118:28: warning: '_outputFile' defined but not used [-Wunused-variable]
  118 | static FILE* _inputFile, * _outputFile;
      |                            ^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 154 ms 396 KB Output is correct
24 Correct 154 ms 384 KB Output is correct
25 Correct 178 ms 504 KB Output is correct
26 Correct 173 ms 384 KB Output is correct
27 Correct 143 ms 504 KB Output is correct
28 Correct 173 ms 504 KB Output is correct
29 Correct 135 ms 524 KB Output is correct
30 Correct 164 ms 504 KB Output is correct
31 Correct 133 ms 384 KB Output is correct
32 Correct 133 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 9208 KB Output is correct
2 Correct 705 ms 9336 KB Output is correct
3 Correct 710 ms 9304 KB Output is correct
4 Correct 693 ms 9208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 155 ms 504 KB Output is correct
24 Correct 155 ms 508 KB Output is correct
25 Correct 174 ms 516 KB Output is correct
26 Correct 177 ms 632 KB Output is correct
27 Correct 144 ms 504 KB Output is correct
28 Correct 175 ms 504 KB Output is correct
29 Correct 131 ms 384 KB Output is correct
30 Correct 165 ms 384 KB Output is correct
31 Correct 132 ms 432 KB Output is correct
32 Correct 132 ms 384 KB Output is correct
33 Incorrect 74 ms 8192 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 154 ms 400 KB Output is correct
24 Correct 154 ms 504 KB Output is correct
25 Correct 174 ms 384 KB Output is correct
26 Correct 174 ms 400 KB Output is correct
27 Correct 143 ms 384 KB Output is correct
28 Correct 173 ms 384 KB Output is correct
29 Correct 134 ms 504 KB Output is correct
30 Correct 164 ms 504 KB Output is correct
31 Correct 132 ms 384 KB Output is correct
32 Correct 131 ms 384 KB Output is correct
33 Correct 513 ms 10824 KB Output is correct
34 Correct 707 ms 22008 KB Output is correct
35 Correct 714 ms 13176 KB Output is correct
36 Correct 697 ms 16888 KB Output is correct
37 Incorrect 77 ms 12152 KB Output isn't correct
38 Halted 0 ms 0 KB -