array 思维+观察

array

观察

观察输入可知

a和b数组中,大部分必定全为0!!!

思维

a 和 b中可多都是0,这样每次循环n还是过不了
1,找到a 和 b 数组中的最大值
2,c中的值一定大于等于 a和b中的最大值
3,考虑a中非零的数和b中非零的数相结合产生的贡献,即

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define int long long
#define fi first
#define se second
#define pb push_back

#define foa(x, y, z) for(int x = (y), ooo = (z); x <= z; ++x)
#define fos(x, y, z) for(int x = (y), ooo = (z); x >= z; --x)
#define ckmax(x, y) ((x) < (y) ? (x) = (y), 1 : 0)
#define ckmin(x, y) ((x) > (y) ? (x) = (y), 1 : 0)

typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
int n, m;
int a[N], b[N], c[N];
void solve()
{
	cin >> n;
    vector<int> va, vb;
    int ma = 0, mb = 0;
    foa(i, 0, n - 1) {
        cin >> a[i];
        if(a[i]) va.pb(i);
        ckmax(ma, a[i]);
    }
    foa(i, 0, n - 1) {
        cin >> b[i];
        if(b[i]) vb.pb(i);
        ckmax(mb, b[i]);
    }
    int mv = max(ma, mb);
    foa(i, 0, n - 1) c[i] = mv;
    for(auto &x : va) {
        for(auto &y : vb) {
            ckmax(c[(x + y) % n], (a[x] + b[y]) % mod);
        }
    }
    foa(i, 0, n - 1) cout << c[i] << " ";
    cout << endl;
}
signed main()
{
	// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
	solve();
    return 0;
}
posted @ 2022-04-29 16:42  1564269628  阅读(30)  评论(0)    收藏  举报