QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#101994 | #5590. Exponent Exchange | joesmitty | WA | 19ms | 4940kb | C++20 | 4.4kb | 2023-05-02 08:37:42 | 2023-05-02 08:37:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
template <typename T>
void pr(vector<T> &v) {
FOR(i, 0, sz(v)) cout << v[i] << " ";
cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
cin >> x;
}
template <typename T>
void re(vector<T> &a) {
FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
re(first);
re(rest...);
}
template <typename T>
void pr(T x) {
cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
cout << first << " ";
pr(rest...);
cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
const ll MOD = 998244353;
#define inf 1e18;
#define INF INT_MAX
long double PI = 4*atan(1);
long double eps = 1e-12;
int main() {
//auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);cin.tie(0);
// ofstream cout("disrupt.out");
// ifstream cin("disrupt.in");
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int b,p; cin >> b >> p;
vector<int> x(p); re(x);
reverse(all(x));
x.pb(0);
vi y(p+1);
bool good = false;
FOR(i,0,p) {
if(!good) {
if(x[i] == 0) y[i] = 0;
else y[i] = b - x[i];
} else {
y[i] = b-1 - x[i];
}
if(x[i] != 0) good = true;
}
vi xlo = x, yhi = y;
vi xhi = x, ylo = y;
// pr(x);
// pr(y);
// cout << "***" << endl;
int dp[2][100000] = {};
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
dp[1][0] = 0;
FOR(t,0,p) {
int dp2[2][100000] = {};
memset(dp2, 0x3f, sizeof(dp2));
//FOR(k,0,2) FOR(j,0,100000) {dp2[k][j] = dp[k][j];}
FOR(i,0,100000) {
if(dp[0][i] < 1e8) {
dp2[0][i] = min(dp2[0][i], dp[0][i] + ylo[t]);
dp2[1][i + xhi[t]] = min(dp2[1][i + xhi[t]], dp[0][i]);
}
if(dp[1][i] < 1e8) {
dp2[0][i] = min(dp2[0][i], dp[1][i] + yhi[t]);
dp2[1][i + xlo[t]] = min(dp2[1][i + xlo[t]], dp[1][i]);
}
}
FOR(k,0,2) FOR(j,0,100000) {dp[k][j] = dp2[k][j];}
// FOR(k,0,2) {
// FOR(j,0,20) {
// cout << dp[k][j] << " ";
// }
// cout << endl;
// }
yhi[t] += xlo[t];
xlo[t] = 0;
int ptr = t;
while(yhi[ptr] == b) {
yhi[ptr] = 0;
yhi[ptr+1]++;
ptr++;
}
// pr(xlo);
// pr(yhi);
// cout << "----" << endl;
xhi[t] += ylo[t];
ylo[t] = 0;
ptr = t;
while(xhi[ptr] == b) {
xhi[ptr] = 0;
xhi[ptr+1]++;
ptr++;
}
// pr(xhi);
// pr(ylo);
// cout << "-----------" << endl;
}
int ans = 1e9;
FOR(i,0,2) {
FOR(j,0,100000) {
if(dp[i][j] < 1e8) {
ans = min(ans, max(j, dp[i][j]));
}
}
}
cout << ans << endl;
// cout << 10 << " " << 1000 << endl;
// FOR(i,0,1000) {
// cout << << " ";
// }
// cout << endl;
// auto stop = chrono::high_resolution_clock::now();
// auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
// cout << duration.count() << endl;
//cin.close();
//cout.close();
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 4940kb
input:
10 5 4 2 7 8 6
output:
7
result:
ok single line: '7'
Test #2:
score: -100
Wrong Answer
time: 19ms
memory: 4924kb
input:
2 100 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 0 0 1 0 1 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1
output:
1
result:
wrong answer 1st lines differ - expected: '19', found: '1'