QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246969 | #7625. Path | ucup-team088# | AC ✓ | 14ms | 12952kb | C++17 | 6.4kb | 2023-11-11 13:08:50 | 2023-11-11 13:08:51 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
#include<chrono>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
//ll mod = 1;
constexpr ll mod = 998244353;
//constexpr ll mod = 1000000007;
const int mod17 = 1000000007;
const ll INF = (ll)mod17 * mod17;
typedef pair<int, int>P;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
using ld = double;
typedef pair<ld, ld> LDP;
const ld eps = 1e-10;
const ld pi = acosl(-1.0);
template<typename T>
void chmin(T& a, T b) {
a = min(a, b);
}
template<typename T>
void chmax(T& a, T b) {
a = max(a, b);
}
template<typename T>
vector<T> vmerge(vector<T>& a, vector<T>& b) {
vector<T> res;
int ida = 0, idb = 0;
while (ida < a.size() || idb < b.size()) {
if (idb == b.size()) {
res.push_back(a[ida]); ida++;
}
else if (ida == a.size()) {
res.push_back(b[idb]); idb++;
}
else {
if (a[ida] < b[idb]) {
res.push_back(a[ida]); ida++;
}
else {
res.push_back(b[idb]); idb++;
}
}
}
return res;
}
template<typename T>
void cinarray(vector<T>& v) {
rep(i, v.size())cin >> v[i];
}
template<typename T>
void coutarray(vector<T>& v) {
rep(i, v.size()) {
if (i > 0)cout << " "; cout << v[i];
}
cout << "\n";
}
ll mod_pow(ll x, ll n, ll m = mod) {
if (n < 0) {
ll res = mod_pow(x, -n, m);
return mod_pow(res, m - 2, m);
}
if (abs(x) >= m)x %= m;
if (x < 0)x += m;
//if (x == 0)return 0;
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
//mod should be <2^31
struct modint {
int n;
modint() :n(0) { ; }
modint(ll m) {
if (m < 0 || mod <= m) {
m %= mod; if (m < 0)m += mod;
}
n = m;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
bool operator<(modint a, modint b) { return a.n < b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= (int)mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += (int)mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 20;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[a - b];
}
ll gcd(ll a, ll b) {
a = abs(a); b = abs(b);
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
template<typename T>
void addv(vector<T>& v, int loc, T val) {
if (loc >= v.size())v.resize(loc + 1, 0);
v[loc] += val;
}
/*const int mn = 2000005;
bool isp[mn];
vector<int> ps;
void init() {
fill(isp + 2, isp + mn, true);
for (int i = 2; i < mn; i++) {
if (!isp[i])continue;
ps.push_back(i);
for (int j = 2 * i; j < mn; j += i) {
isp[j] = false;
}
}
}*/
//[,val)
template<typename T>
auto prev_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
if (res == st.begin())return st.end();
res--; return res;
}
//[val,)
template<typename T>
auto next_itr(set<T>& st, T val) {
auto res = st.lower_bound(val);
return res;
}
using mP = pair<modint, modint>;
mP operator+(mP a, mP b) {
return { a.first + b.first,a.second + b.second };
}
mP operator+=(mP& a, mP b) {
a = a + b; return a;
}
mP operator-(mP a, mP b) {
return { a.first - b.first,a.second - b.second };
}
mP operator-=(mP& a, mP b) {
a = a - b; return a;
}
LP operator+(LP a, LP b) {
return { a.first + b.first,a.second + b.second };
}
LP operator+=(LP& a, LP b) {
a = a + b; return a;
}
LP operator-(LP a, LP b) {
return { a.first - b.first,a.second - b.second };
}
LP operator-=(LP& a, LP b) {
a = a - b; return a;
}
mt19937 mt(time(0));
const string drul = "DRUL";
string senw = "SENW";
//DRUL,or SENW
//int dx[4] = { 1,0,-1,0 };
//int dy[4] = { 0,1,0,-1 };
//------------------------------------
void solve() {
int n, m; cin >> n >> m;
vector<ll> a(n), b(m);
rep(i, n)cin >> a[i];
rep(i, m)cin >> b[i];
ll ans = 0;
rep(i, n - 1)ans += abs(a[i] - a[i + 1]);
rep(i, m - 1)ans += abs(b[i] - b[i + 1]);
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed<<setprecision(10);
//init_f();
//init();
//init2();
//while(true)
//expr();
//int t; cin >> t; rep(i, t)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11720kb
input:
4 4 1 3 3 1 8 10 8 5
output:
11
result:
ok single line: '11'
Test #2:
score: 0
Accepted
time: 4ms
memory: 11788kb
input:
4 2 5 7 8 10 10 3
output:
12
result:
ok single line: '12'
Test #3:
score: 0
Accepted
time: 14ms
memory: 12936kb
input:
100000 100000 18394 24233 357 52481 18043 49271 55052 81632 30068 16351 74661 71867 28721 46743 54031 18957 25470 94751 25746 62355 22561 5373 99009 49079 48551 48807 41085 90981 82649 23014 74376 54517 95181 9445 10083 85937 95809 31477 38527 68803 91671 55251 17894 43472 69255 20256 21718 38213 12...
output:
6671609257
result:
ok single line: '6671609257'
Test #4:
score: 0
Accepted
time: 14ms
memory: 12952kb
input:
100000 100000 49849 61189 44964 89719 54861 59757 54071 37516 69885 42727 69469 60593 62981 34185 36641 36826 47251 10501 71167 44261 42977 35866 72991 35233 39003 96298 75153 25421 43153 6520 11321 87601 92801 65989 74932 30242 13385 36407 76034 97112 44941 93553 41606 7201 71725 45052 75732 72300 ...
output:
6672086237
result:
ok single line: '6672086237'
Test #5:
score: 0
Accepted
time: 12ms
memory: 12876kb
input:
100000 90000 1 62782 1 26382 1 69310 1 6311 1 96861 1 14370 1 58980 1 48109 1 64865 1 5033 1 24391 1 28997 1 48373 1 13006 1 12285 1 16585 1 8426 1 27406 1 8738 1 90929 1 41126 1 71171 1 31553 1 77113 1 82309 1 75665 1 63265 1 74113 1 47691 1 8004 1 41589 1 4582 1 76800 1 67765 1 57435 1 53126 1 883...
output:
9473046647
result:
ok single line: '9473046647'
Test #6:
score: 0
Accepted
time: 13ms
memory: 12816kb
input:
90000 100000 1 29919 1 19450 1 15481 1 12155 1 22315 1 13158 1 25727 1 195 1 23167 1 18981 1 11091 1 17235 1 9448 1 11997 1 17043 1 31138 1 10513 1 23390 1 1881 1 27821 1 11028 1 26154 1 19893 1 6553 1 1936 1 32053 1 91 1 8858 1 28924 1 32233 1 26776 1 18195 1 5946 1 20077 1 12939 1 9983 1 28015 1 2...
output:
3109377821
result:
ok single line: '3109377821'
Test #7:
score: 0
Accepted
time: 8ms
memory: 12856kb
input:
90000 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000...
output:
18999610002
result:
ok single line: '18999610002'
Test #8:
score: 0
Accepted
time: 12ms
memory: 12884kb
input:
100000 90000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000 1 100000...
output:
18999610002
result:
ok single line: '18999610002'
Test #9:
score: 0
Accepted
time: 7ms
memory: 12428kb
input:
89587 32731 8066 30223 13728 32177 24547 24078 14708 6400 2772 4833 30027 25808 32423 12769 10277 7920 20862 18932 29030 17666 14084 31337 1068 19072 28255 31011 9440 28668 19552 17402 9483 8108 13821 350 20843 29477 7938 21565 1607 18023 24835 10023 24063 31770 32405 12977 11751 22295 9918 17175 17...
output:
1337025965
result:
ok single line: '1337025965'
Test #10:
score: 0
Accepted
time: 0ms
memory: 11812kb
input:
20906 9083 26870 17089 29290 17540 8801 26106 13969 6620 15163 22028 9916 14194 2672 6591 19430 27240 12403 30800 5800 19971 21563 21095 9307 3146 12684 1864 24445 3280 23671 14925 32597 1486 24100 3220 10970 9076 3791 7925 17106 14721 20753 28727 5943 13074 4705 27523 3038 13495 13530 15128 28763 9...
output:
328067052
result:
ok single line: '328067052'
Extra Test:
score: 0
Extra Test Passed