ccf-csp

 

 

 

 

 

 

 

 

 

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 # define N 10000
 5 int main(){
 6     
 7     
 8     int m,n;
 9     cin>>n>>m;
10     
11     
12     int res1[N]  = {0} ;
13     int res2[N]  = {0} ;
14     
15     
16     int dep[N] = {0};
17     int day[N] = {0};
18     for(int i  = 1 ; i <= m ; ++i){
19         cin>>dep[i];
20     }
21     
22         for(int i  = 1 ; i <= m ; ++i){
23         cin>>day[i];
24     }
25     
26     
27     
28     bool flag = false;
29     
30     for(int i = m  ; i >= 1 ; --i){
31         int t  = 0 ; 
32             
33         t+= day[i];
34         if(dep[i]!=0){
35             
36             int j  = i ;
37             
38             
39             
40             while(dep[j] != 0){
41                 int d = dep[j];
42                 t += day[d];
43                 j = d;
44             }
45             
46             
47             if(t > n){
48                 flag = true;
49             }else {
50             
51                 res2[i] = n - t + 1;
52             }
53             
54         }else{
55                 res2[i] = n - t + 1;
56         }
57         
58             res1[i] = t - day[i]  + 1;
59         
60         
61         
62     }
63     
64     
65     for(int i  =1 ; i <= m - 1 ; ++i){
66         cout<<res1[i]<<" ";
67         
68     }
69     cout<<  res1[m] ;
70     
71     if(!flag){
72         cout<<endl;
73         for(int i  =1 ; i <= m - 1 ; ++i){
74         cout<<res2[i]<<" ";
75         
76         }
77     
78         cout<<res2[m];
79     }
80     
81     
82 //    test:
83 //    cout<<"------"<<endl;
84 //    for(int i  =1 ; i <= m - 1 ; ++i){
85 //        cout<<res2[i]<<" ";
86 //        
87 //    }
88 //    cout<<  res2[m] ;
89     
90     return 0;
91 }

70%。草

posted @ 2023-02-19 13:22  CSU_YAM  阅读(33)  评论(0)    收藏  举报