Please sign in first.
Submission #67787678
Source Code Expand
#include<bits/stdc++.h>
#define cmin(a,b) a=std::min(a,b)
#define cmax(a,b) a=std::max(a,b)
#define maxn 1000006
#define mod
#define inf
#define int long long
int T,n,a[maxn];
std::multiset<int> pos;
struct info{
int val,id;
bool operator <(info oth) const{
if(val==oth.val){
return id<oth.id;
}
return val<oth.val;
}
};
std::multiset<info> st;
signed main(){
scanf("%lld",&T);
while(T--){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
pos.insert(i);
st.insert({a[i],i});
}
int ans=0;
for(int i=1;i<=n-1;i++){
info tmp=*st.begin();
int id=tmp.id,val=tmp.val;
st.erase(tmp),pos.erase(id);
auto p1=pos.lower_bound(id),p2=p1;
int pid=-1;
if(p1==pos.begin()){
pid=*p2;
}else{
p1--;
if(p2==pos.end()){
pid=*p1;
}else if(a[*p1]<=a[*p2]){
pid=*p1;
}else{
pid=*p2;
}
}
st.erase({a[pid],pid});
ans+=a[pid]-val;
a[pid]++;
st.insert({a[pid],pid});
}
printf("%lld\n",ans);
st.clear(),pos.clear();
}
return 0;
}
/*
*/
Submission Info
| Submission Time | |
|---|---|
| Task | A - Merge and Increment |
| User | huanghongjun |
| Language | C++ 20 (gcc 12.2) |
| Score | 0 |
| Code Size | 1102 Byte |
| Status | WA |
| Exec Time | 449 ms |
| Memory | 27316 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%lld",&T);
| ~~~~~^~~~~~~~~~~
Main.cpp:23:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
Main.cpp:25:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||||
|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 0 / 700 | ||||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_00.txt |
| All | 00_sample_00.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 01_small_10.txt, 01_small_11.txt, 01_small_12.txt, 01_small_13.txt, 01_small_14.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 03_sorted_00.txt, 03_sorted_01.txt, 03_sorted_02.txt, 03_sorted_03.txt, 03_sorted_04.txt, 03_sorted_05.txt, 04_almost_sorted_00.txt, 04_almost_sorted_01.txt, 04_almost_sorted_02.txt, 04_almost_sorted_03.txt, 04_almost_sorted_04.txt, 04_almost_sorted_05.txt, 05_same_00.txt, 05_same_01.txt, 05_same_02.txt, 06_corner_00.txt, 06_corner_01.txt, 06_corner_02.txt, 07_hack_1_00.txt, 07_hack_1_01.txt, 07_hack_1_02.txt, 07_hack_1_03.txt, 07_hack_1_04.txt, 08_hack_2_00.txt, 08_hack_2_01.txt, 08_hack_2_02.txt, 08_hack_2_03.txt, 08_hack_2_04.txt, 09_hack_3_00.txt, 09_hack_3_01.txt, 09_hack_3_02.txt, 09_hack_3_03.txt, 09_hack_3_04.txt, 09_hack_3_05.txt, 09_hack_3_06.txt, 09_hack_3_07.txt, 09_hack_3_08.txt, 09_hack_3_09.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_00.txt | AC | 1 ms | 3760 KiB |
| 01_small_00.txt | WA | 37 ms | 3696 KiB |
| 01_small_01.txt | WA | 36 ms | 3824 KiB |
| 01_small_02.txt | WA | 26 ms | 3760 KiB |
| 01_small_03.txt | AC | 50 ms | 3696 KiB |
| 01_small_04.txt | AC | 51 ms | 3688 KiB |
| 01_small_05.txt | AC | 52 ms | 3656 KiB |
| 01_small_06.txt | AC | 53 ms | 3828 KiB |
| 01_small_07.txt | AC | 62 ms | 3684 KiB |
| 01_small_08.txt | AC | 76 ms | 3884 KiB |
| 01_small_09.txt | AC | 36 ms | 3820 KiB |
| 01_small_10.txt | AC | 36 ms | 3756 KiB |
| 01_small_11.txt | WA | 38 ms | 3772 KiB |
| 01_small_12.txt | WA | 38 ms | 3884 KiB |
| 01_small_13.txt | WA | 54 ms | 3684 KiB |
| 01_small_14.txt | WA | 72 ms | 3664 KiB |
| 02_random_00.txt | AC | 308 ms | 24224 KiB |
| 02_random_01.txt | AC | 362 ms | 27252 KiB |
| 02_random_02.txt | AC | 316 ms | 23716 KiB |
| 02_random_03.txt | AC | 383 ms | 27112 KiB |
| 02_random_04.txt | AC | 355 ms | 26280 KiB |
| 02_random_05.txt | AC | 369 ms | 27248 KiB |
| 02_random_06.txt | AC | 196 ms | 18204 KiB |
| 02_random_07.txt | AC | 372 ms | 27088 KiB |
| 02_random_08.txt | AC | 195 ms | 18088 KiB |
| 02_random_09.txt | AC | 376 ms | 27192 KiB |
| 03_sorted_00.txt | AC | 124 ms | 27184 KiB |
| 03_sorted_01.txt | AC | 132 ms | 27064 KiB |
| 03_sorted_02.txt | AC | 133 ms | 27088 KiB |
| 03_sorted_03.txt | AC | 125 ms | 27196 KiB |
| 03_sorted_04.txt | AC | 133 ms | 27068 KiB |
| 03_sorted_05.txt | AC | 133 ms | 27256 KiB |
| 04_almost_sorted_00.txt | AC | 126 ms | 27196 KiB |
| 04_almost_sorted_01.txt | AC | 132 ms | 27112 KiB |
| 04_almost_sorted_02.txt | AC | 133 ms | 27188 KiB |
| 04_almost_sorted_03.txt | AC | 127 ms | 27092 KiB |
| 04_almost_sorted_04.txt | AC | 132 ms | 27088 KiB |
| 04_almost_sorted_05.txt | AC | 132 ms | 27060 KiB |
| 05_same_00.txt | WA | 176 ms | 27124 KiB |
| 05_same_01.txt | WA | 181 ms | 27120 KiB |
| 05_same_02.txt | WA | 185 ms | 27088 KiB |
| 06_corner_00.txt | WA | 189 ms | 27252 KiB |
| 06_corner_01.txt | AC | 133 ms | 27104 KiB |
| 06_corner_02.txt | AC | 128 ms | 27124 KiB |
| 07_hack_1_00.txt | WA | 172 ms | 27248 KiB |
| 07_hack_1_01.txt | WA | 184 ms | 27088 KiB |
| 07_hack_1_02.txt | WA | 171 ms | 27200 KiB |
| 07_hack_1_03.txt | WA | 172 ms | 27316 KiB |
| 07_hack_1_04.txt | WA | 178 ms | 27196 KiB |
| 08_hack_2_00.txt | WA | 191 ms | 27252 KiB |
| 08_hack_2_01.txt | WA | 189 ms | 27016 KiB |
| 08_hack_2_02.txt | WA | 191 ms | 27124 KiB |
| 08_hack_2_03.txt | WA | 194 ms | 27056 KiB |
| 08_hack_2_04.txt | WA | 190 ms | 27192 KiB |
| 09_hack_3_00.txt | WA | 178 ms | 27196 KiB |
| 09_hack_3_01.txt | WA | 175 ms | 27068 KiB |
| 09_hack_3_02.txt | WA | 203 ms | 27092 KiB |
| 09_hack_3_03.txt | WA | 220 ms | 27252 KiB |
| 09_hack_3_04.txt | WA | 296 ms | 27200 KiB |
| 09_hack_3_05.txt | WA | 314 ms | 27020 KiB |
| 09_hack_3_06.txt | WA | 427 ms | 27096 KiB |
| 09_hack_3_07.txt | WA | 406 ms | 27064 KiB |
| 09_hack_3_08.txt | WA | 449 ms | 27124 KiB |
| 09_hack_3_09.txt | WA | 390 ms | 27188 KiB |