Last active
August 29, 2015 14:14
-
-
Save akouryy/ff09490fb5ad6816f472 to your computer and use it in GitHub Desktop.
ABC018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++) | |
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++) | |
using namespace std; | |
int main(){ | |
int A, B, C; | |
cin >> A >> B >> C; | |
cout << 1 + (A < B) + (A < C) << endl; | |
cout << 1 + (B < A) + (B < C) << endl; | |
cout << 1 + (C < A) + (C < B) << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++) | |
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++) | |
using namespace std; | |
int main(){ | |
string S; | |
cin >> S; | |
int N; | |
cin >> N; | |
times(N, i){ | |
int l, r; | |
cin >> l >> r; | |
--l; --r; | |
upto(l, (l + r - 1) / 2, i){ | |
swap(S[i], S[l + r - i]); | |
} | |
} | |
cout << S << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++) | |
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++) | |
#define unless(c) if(!(c)) | |
#define until(c) while(!(c)) | |
using namespace std; | |
int main(){ | |
int R, C, K; | |
cin >> R >> C >> K; | |
vector<vector<bool>> S(R, vector<bool>(C)); | |
vector<vector<int>> pyon(R, vector<int>(C)), | |
kanou(R, vector<int>(C)), | |
machi(R, vector<int>(C)); | |
times(R, i){ | |
times(C, j){ | |
char c; | |
cin >> c; | |
S[i][j] = c == 'o'; | |
} | |
} | |
times(R, i){ | |
times(C, j){ | |
unless(S[i][j]) | |
pyon[i][j] = 0; | |
else unless(i && j) | |
pyon[i][j] = 1; | |
else | |
pyon[i][j] = pyon[i - 1][j - 1] + 1; | |
} | |
} | |
times(R, i){ | |
times(C, j){ | |
if(pyon[i][j] < K - 1) | |
machi[i][j] = 0; | |
else if(i == 0 || j == C - 1) | |
machi[i][j] = 1; | |
else | |
machi[i][j] = machi[i - 1][j + 1] + 1; | |
if(pyon[i][j] < K) | |
kanou[i][j] = 0; | |
else if(i == 0 || j == C - 1) | |
kanou[i][j] = 1; | |
else | |
kanou[i][j] = kanou[i - 1][j + 1] + 1; | |
} | |
} | |
/* | |
times(R, i){ | |
times(C, j) | |
cout << pyon[i][j] << " "; | |
cout << endl; | |
} | |
cout << endl; | |
times(R, i){ | |
times(C, j) | |
cout << kanou[i][j] << " "; | |
cout << endl; | |
} | |
cout << endl; | |
times(R, i){ | |
times(C, j) | |
cout << machi[i][j] << " "; | |
cout << endl; | |
} | |
*/ | |
int ans = 0; | |
uptil(1, R, i){ | |
times(C, j){ | |
if(kanou[i][j] >= K && machi[i - 1][j] >= K - 1) ans++; | |
} | |
} | |
cout << ans << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++) | |
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++) | |
#define unless(c) if(!(c)) | |
#define until(c) while(!(c)) | |
using namespace std; | |
int N, M, P, Q, R; | |
vector<int> x, y, z; | |
int pyonpyon(int i, const vector<bool>& girls, int true_count){ | |
vector<int> happiness(M, 0); | |
times(R, i){ | |
if(girls[x[i]]) happiness[y[i]] += z[i]; | |
} | |
sort(happiness.begin(), happiness.end(), greater<int>()); | |
int ret = 0; | |
times(Q, i) ret += happiness[i]; | |
return ret; | |
} | |
int pyon(int i, vector<bool>& girls, int true_count){ | |
if(i == N){ | |
if(true_count == P){ | |
return pyonpyon(0, girls, 0); | |
} | |
else return -1; | |
}else{ | |
if(true_count > P) return -1; | |
girls[i] = true; | |
int t = pyon(i + 1, girls, true_count + 1); | |
girls[i] = false; | |
return max(t, pyon(i + 1, girls, true_count)); | |
} | |
} | |
int main(){ | |
cin >> N >> M >> P >> Q >> R; | |
x = vector<int>(R); | |
y = vector<int>(R); | |
z = vector<int>(R); | |
times(R, i){ | |
cin >> x[i] >> y[i] >> z[i]; | |
x[i]--; | |
y[i]--; | |
} | |
auto g = vector<bool>(N, false); | |
cout << pyon(0, g, 0) << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define times(n, i) uptil(0, n, i) | |
#define upto(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i <= _##i; i++) | |
#define uptil(f, t, i) for(auto _##i = (t), i = decltype(_##i)(f); i < _##i; i++) | |
#define unless(c) if(!(c)) | |
#define until(c) while(!(c)) | |
using namespace std; | |
int N, M, P, Q, R; | |
vector<int> x, y, z; | |
int calc(const vector<bool>& girls, const vector<bool>& boys){ | |
/* | |
times(N, i) cout << (int)girls[i] << " "; | |
cout << endl; | |
times(M, i) cout << (int)boys[i] << " "; | |
cout << endl; | |
*/ | |
int ret = 0; | |
times(R, i){ | |
//cout << (girls[x[i]] && boys[y[i]]) << " "; | |
if(girls[x[i]] && boys[y[i]]) ret += z[i]; | |
} | |
/* | |
cout << endl; | |
cout << ret << endl << endl; | |
*/ | |
return ret; | |
} | |
int pyonpyon(int i, const vector<bool>& girls, vector<bool>& boys, int true_count){ | |
if(i == M){ | |
if(true_count == Q) | |
return calc(girls, boys); | |
else return -1; | |
}else{ | |
if(true_count > Q) return -1; | |
boys[i] = true; | |
int t = pyonpyon(i + 1, girls, boys, true_count + 1); | |
boys[i] = false; | |
return max(t, pyonpyon(i + 1, girls, boys, true_count)); | |
} | |
} | |
int pyon(int i, vector<bool>& girls, int true_count){ | |
if(i == N){ | |
if(true_count == P){ | |
auto m = vector<bool>(M, false); | |
return pyonpyon(0, girls, m, 0); | |
} | |
else return -1; | |
}else{ | |
if(true_count > P) return -1; | |
girls[i] = true; | |
int t = pyon(i + 1, girls, true_count + 1); | |
girls[i] = false; | |
return max(t, pyon(i + 1, girls, true_count)); | |
} | |
} | |
int main(){ | |
cin >> N >> M >> P >> Q >> R; | |
x = vector<int>(R); | |
y = vector<int>(R); | |
z = vector<int>(R); | |
times(R, i){ | |
cin >> x[i] >> y[i] >> z[i]; | |
x[i]--; | |
y[i]--; | |
} | |
auto g = vector<bool>(N, false); | |
cout << pyon(0, g, 0) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment