-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
257 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) | ||
#define REPR(i,n) for(int i=n;i>=0;i--) | ||
#define FOR(i,a,b) for(int i=(a);i<(b);++i) | ||
#define FORR(i,a,b) for(int i=(a);i>=(b);--i) | ||
#define ALL(x) (x).begin(),(x).end() | ||
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); | ||
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl | ||
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl | ||
#define PRINT_DOUBLE(n, x) cout << std::fixed << std::setprecision(n) << x << endl; | ||
|
||
void _main() { | ||
int N; | ||
cin >> N; | ||
|
||
vector<vector<int>> D(N, vector<int>(N)); | ||
REP(i, N) REP(j, N) cin >> D[i][j]; | ||
|
||
int Q; | ||
cin >> Q; | ||
|
||
vector<int> P(Q); | ||
REP(i, Q) cin >> P[i]; | ||
|
||
vector<vector<int>> s(N+1, vector<int>(N+1)); | ||
REP(i, N+1) s[i][0] = 0; | ||
REP(i, N+1) s[0][i] = 0; | ||
|
||
REP(i, N) { | ||
REP(j, N) { | ||
s[i+1][j+1] = D[i][j] + s[i+1][j] + s[i][j+1] - s[i][j]; | ||
} | ||
} | ||
|
||
REP(i, Q) { | ||
int res = 0; | ||
FOR(j, 1, P[i]+1) { | ||
int H = j; | ||
int W = min(P[i] / H, N); | ||
if (H > N) continue; | ||
|
||
// cout << "H: " << H << ", W: " << W << endl; | ||
FOR(t, 1, N+1) { | ||
FOR(l, 1, N+1) { | ||
int b = t + H - 1; | ||
int r = l + W - 1; | ||
if (b > N || r > N) continue; | ||
// cout << t << " " << l << " " << b << " " << r << endl; | ||
|
||
res = max(res, s[b][r] - s[t-1][r] - s[b][l-1] + s[t-1][l-1]);; | ||
} | ||
} | ||
} | ||
cout << res << endl; | ||
} | ||
|
||
} | ||
|
||
int main() { | ||
_main(); | ||
_main(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
3 | ||
3 2 1 | ||
2 2 1 | ||
1 1 1 | ||
3 | ||
1 | ||
4 | ||
9 | ||
|
||
3 | ||
1 1 1 | ||
1 1 1 | ||
9 9 9 | ||
1 | ||
4 | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) | ||
#define REPR(i,n) for(int i=n;i>=0;i--) | ||
#define FOR(i,a,b) for(int i=(a);i<(b);++i) | ||
#define FORR(i,a,b) for(int i=(a);i>=(b);--i) | ||
#define ALL(x) (x).begin(),(x).end() | ||
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); | ||
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl | ||
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl | ||
#define PRINT_DOUBLE(n, x) cout << std::fixed << std::setprecision(n) << x << endl; | ||
|
||
|
||
int N, Q; | ||
string S; | ||
|
||
void _main() { | ||
cin >> N >> Q; | ||
cin >> S; | ||
|
||
int a[N+1]; | ||
a[0] = a[1] = 0; | ||
FOR(i, 2, N+1) { | ||
a[i] = a[i-1]; | ||
if (S[i-2] == 'A' && S[i-1] == 'C') ++a[i]; | ||
// cout << a[i] << endl; | ||
} | ||
|
||
int l, r; | ||
REP(i, Q) { | ||
cin >> l >> r; | ||
cout << a[r] - a[l] << endl; | ||
} | ||
} | ||
|
||
int main() { | ||
_main(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
8 3 | ||
ACACTACG | ||
3 7 | ||
2 3 | ||
1 8 | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) | ||
#define REPR(i,n) for(int i=n;i>=0;i--) | ||
#define FOR(i,a,b) for(int i=(a);i<(b);++i) | ||
#define FORR(i,a,b) for(int i=(a);i>=(b);--i) | ||
#define ALL(x) (x).begin(),(x).end() | ||
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); | ||
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl | ||
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl | ||
#define PRINT_DOUBLE(n, x) cout << std::fixed << std::setprecision(n) << x << endl; | ||
|
||
int N; | ||
|
||
void _main() { | ||
cin >> N; | ||
|
||
int A[N+1]; | ||
FOR(i, 1, N+1) cin >> A[i]; | ||
|
||
ll s[N+1]; | ||
s[0] = 0; | ||
|
||
REP(i, N) { | ||
s[i+1] = s[i] + A[i+1]; | ||
} | ||
|
||
// これではやはりTLE | ||
// ll count = 0; | ||
// FOR(i, 0, N) { | ||
// FOR(j, i+1, N+1) { | ||
// if (s[j] - s[i] == 0) ++count; | ||
// } | ||
// } | ||
|
||
std::map<ll, ll> countMap; | ||
// s[0]も含めないと元々総和が0の部分列を取りそこねる | ||
FOR(i, 0, N+1) ++countMap[s[i]]; | ||
|
||
ll res = 0; | ||
for (auto &p : countMap) { | ||
res += p.second * (p.second - 1) / 2; | ||
} | ||
|
||
cout << res << endl; | ||
} | ||
|
||
int main() { | ||
_main(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
6 | ||
1 3 -4 2 2 -2 | ||
|
||
7 | ||
1 -1 1 -1 1 -1 1 | ||
|
||
5 | ||
1 -2 3 -4 5 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
using ll = long long; | ||
|
||
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) | ||
#define REPR(i,n) for(int i=n;i>=0;i--) | ||
#define FOR(i,a,b) for(int i=(a);i<(b);++i) | ||
#define FORR(i,a,b) for(int i=(a);i>=(b);--i) | ||
#define ALL(x) (x).begin(),(x).end() | ||
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); | ||
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl | ||
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl | ||
#define PRINT_DOUBLE(n, x) cout << std::fixed << std::setprecision(n) << x << endl; | ||
|
||
|
||
void _main() { | ||
int H, W; | ||
cin >> H >> W; | ||
|
||
vector<vector<int>> a(H, vector<int>(W)); | ||
REP(i, H) REP(j, W) cin >> a[i][j]; | ||
|
||
vector<vector<int>> s(H+1, vector<int>(W+1)); | ||
REP(i, H+1) s[i][0] = 0; | ||
REP(j, W+1) s[0][j] = 0; | ||
|
||
REP(i, H) { | ||
REP(j, W) { | ||
s[i+1][j+1] = a[i][j] + s[i+1][j] + s[i][j+1] - s[i][j]; | ||
} | ||
} | ||
|
||
int Q; | ||
cin >> Q; | ||
|
||
int t, b, l, r; | ||
REP(i, Q) { | ||
cin >> t >> b >> l >> r; | ||
cout << s[b][r] - s[b][l] - s[t][r] + s[t][l] << endl; | ||
} | ||
} | ||
|
||
int main() { | ||
_main(); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
4 5 | ||
1 8 7 3 2 | ||
9 1 3 4 6 | ||
3 5 8 1 4 | ||
2 7 3 2 5 | ||
3 | ||
1 3 2 5 | ||
0 2 1 3 | ||
0 4 0 5 |