답안 #1112114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112114 2024-11-13T16:38:57 Z lam 수확 (JOI20_harvest) C++14
5 / 100
1458 ms 337232 KB
#include<bits/stdc++.h>
#define ll long long
#define ntr "\n"
#define mod (ll)(1e9+7)
#define taskname ""
#define frep freopen(taskname".inp","r",stdin); freopen(taskname".out","w",stdout);
using namespace std;
ll a[5001],b[5001];
ll n,m,l,c,q;
vector<pair<ll,ll>> adj[7001];
ll loop1[7001][3001];
ll loop2[7001][3001];
ll vis[7001];
ll par;
void dfs(ll u,ll dist){
    if(vis[u]>=2) return ;
    vis[u]++;
    if(vis[u]==1) loop1[u][par]=dist;
    else loop2[u][par]=dist;
    for(auto [v,w]:adj[u]){
        dfs(v,dist+w);
    }
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //frep;
    cin>>n>>m>>l>>c;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++) cin>>b[i];
    for(int i=1;i<=n;i++){
        ll t=((a[i]-c)%l+l)%l;
        ll pos=upper_bound(a+1,a+n+1,t)-a-1;
        if(pos==0) pos=n;
        //if(i==j) continue;
        ll v=((a[i]-a[pos])%l+l)%l;
        ll cost=(c-v+l-1)/l*l+v;
//        cout<<i<<' '<<pos<<' '<<mn<<ntr;
        adj[i].push_back({pos,cost});
    }
    for(int i=1;i<=m;i++){
        ll v=upper_bound(a+1,a+n+1,b[i])-a-1;
        if(v==0) v=n;
        ll cost=((b[i]-a[v])%l+l)%l;
        adj[i+n].push_back({v,cost});
//        cout<<i<<' '<<v<<' '<<cost<<ntr;
    }
    memset(loop1,0x3f,sizeof(loop1));
    memset(loop2,0x3f,sizeof(loop2));
    for(int i=1;i<=m;i++){
        par=i;
        dfs(i+n,0);
        for(int j=1;j<=n+m;j++) vis[j]=0;
    }
//    for(int i=1;i<=n;i++){
//        for(int j=1;j<=m;j++){
//            cout<<loop1[i][j]<<' ';
//        }
//        cout<<ntr;
//    }
    cin>>q;
    for(int i=1;i<=q;i++){
        ll u,t;
        cin>>u>>t;
        ll ans=0;
        for(int j=1;j<=m;j++){
            if(loop1[u][j]>t) continue;
            ans++;
            ll diff=loop2[u][j]-loop1[u][j];
            //cout<<diff<<' ';
            ans+=(t-loop1[u][j])/diff;
        }
        cout<<ans<<ntr;
    }
}

Compilation message

harvest.cpp: In function 'void dfs(long long int, long long int)':
harvest.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |     for(auto [v,w]:adj[u]){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 329544 KB Output is correct
2 Correct 58 ms 329800 KB Output is correct
3 Correct 68 ms 329732 KB Output is correct
4 Correct 64 ms 329928 KB Output is correct
5 Correct 88 ms 330000 KB Output is correct
6 Correct 89 ms 329904 KB Output is correct
7 Correct 90 ms 329824 KB Output is correct
8 Correct 58 ms 329800 KB Output is correct
9 Correct 60 ms 329800 KB Output is correct
10 Correct 59 ms 329692 KB Output is correct
11 Correct 56 ms 329800 KB Output is correct
12 Correct 177 ms 330056 KB Output is correct
13 Correct 449 ms 330056 KB Output is correct
14 Correct 122 ms 330056 KB Output is correct
15 Correct 73 ms 329956 KB Output is correct
16 Correct 75 ms 329896 KB Output is correct
17 Correct 76 ms 329788 KB Output is correct
18 Correct 69 ms 329804 KB Output is correct
19 Correct 67 ms 329940 KB Output is correct
20 Correct 69 ms 329984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1458 ms 337232 KB Output is correct
2 Runtime error 16 ms 1104 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 329544 KB Output is correct
2 Correct 58 ms 329800 KB Output is correct
3 Correct 68 ms 329732 KB Output is correct
4 Correct 64 ms 329928 KB Output is correct
5 Correct 88 ms 330000 KB Output is correct
6 Correct 89 ms 329904 KB Output is correct
7 Correct 90 ms 329824 KB Output is correct
8 Correct 58 ms 329800 KB Output is correct
9 Correct 60 ms 329800 KB Output is correct
10 Correct 59 ms 329692 KB Output is correct
11 Correct 56 ms 329800 KB Output is correct
12 Correct 177 ms 330056 KB Output is correct
13 Correct 449 ms 330056 KB Output is correct
14 Correct 122 ms 330056 KB Output is correct
15 Correct 73 ms 329956 KB Output is correct
16 Correct 75 ms 329896 KB Output is correct
17 Correct 76 ms 329788 KB Output is correct
18 Correct 69 ms 329804 KB Output is correct
19 Correct 67 ms 329940 KB Output is correct
20 Correct 69 ms 329984 KB Output is correct
21 Correct 1458 ms 337232 KB Output is correct
22 Runtime error 16 ms 1104 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -