Skip to content

Instantly share code, notes, and snippets.

@oyakodon
Created May 15, 2016 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oyakodon/642db637f9230d13346f1fb70a3ee7aa to your computer and use it in GitHub Desktop.
Save oyakodon/642db637f9230d13346f1fb70a3ee7aa to your computer and use it in GitHub Desktop.
ABC037 / C++14
#pragma region Template
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
#pragma endregion
int main() {
// --- I/O 高速化 ---
cin.tie(0);
ios::sync_with_stdio(false);
// --- ここまで ---
int A, B, C;
cin >> A >> B >> C;
int i = max(C / A, C / B);
int max = i;
while (i--) {
int x = C - (A * i);
max = std::max(x / C + i, max);
}
cout << max << "\n";
return 0;
}
#pragma region Template
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
#pragma endregion
int main() {
// --- I/O 高速化 ---
cin.tie(0);
ios::sync_with_stdio(false);
// --- ここまで ---
int N, Q;
cin >> N >> Q;
vector<int> v(N);
while (Q--) {
int l, r, t;
cin >> l >> r >> t;
l--; r--;
for (int i = l; i <= r; i++)
v[i] = t;
}
for (auto item : v) {
cout << item << "\n";
}
return 0;
}
#pragma region Template
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
#pragma endregion
int main() {
// --- I/O 高速化 ---
cin.tie(0);
ios::sync_with_stdio(false);
// --- ここまで ---
int N, K;
cin >> N >> K;
long ans = 0;
vector<int> v(N);
for (int i = 0; i < N; i++) {
int a;
cin >> a;
v[i] = a;
}
for (int i = 0; i < N; i++) {
int mul = K;
mul -= max(0, K - i - 1);
mul -= max(0, K - (N - i));
ans += (long)v[i] * mul;
}
cout << ans << "\n";
return 0;
}
#pragma region Template
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;
#pragma endregion
int H, W;
vector<vector<int>> a;
vector<vector<int>> dp;
int dfs(int x, int y) {
if (dp[x][y] != -1)
return dp[x][y];
long ret = 1;
for (int i = 0; i < 4; i++) {
int vx = x + VX[i];
int vy = y + VY[i];
if (vx < 0 || vy < 0 || vx >= H || vy >= W)
continue;
if (a[x][y] >= a[vx][vy])
continue;
ret += dfs(vx, vy);
}
dp[x][y] = ret % MOD;
return dp[x][y];
}
int main() {
// --- I/O 高速化 ---
cin.tie(0);
ios::sync_with_stdio(false);
// --- ここまで ---
cin >> H >> W;
for (int i = 0; i < H; i++) {
vector<int> v1;
for (int j = 0; j < W; j++) {
int n;
cin >> n;
v1.push_back(n);
}
a.push_back(v1);
}
for (int i = 0; i < H; i++) {
vector<int> v1;
for (int j = 0; j < W; j++) {
v1.push_back(-1);
}
dp.push_back(v1);
}
long ans = 0;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
ans += dfs(i, j);
}
}
ans %= MOD;
cout << ans << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment