QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#446448 | #8528. Chords | ryanguorocket | WA | 2ms | 6000kb | C++17 | 4.2kb | 2024-06-17 10:48:31 | 2024-06-17 10:48:31 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <cstdint>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pd;
typedef pair<ld, ld> pld;
typedef tuple<int, int, int> ti;
typedef tuple<ll, ll, ll> tll;
typedef tuple<double, double, double> td;
typedef complex<double> cd;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> bbst;
mt19937 g1;
int get_random_int(int a, int b) {
return uniform_int_distribution<int>(a, b)(g1);
}
//const ll MOD = 100000000105583;
//const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int MOD = 1000003;
struct Mint {
int v;
Mint() {v = 0;}
Mint(int nv) {v = nv;}
Mint(const Mint &a) {v = a.v;}
Mint pow(int a) {
long long ret = 1;
long long base = v;
if(a < 0) {
a = -a;
base = Mint(v).inv().v;
}
while(a > 0) {
if(a & 1) ret = (ret * base) % MOD;
base = (base * base) % MOD;
a >>= 1;
}
return Mint((int)ret);
}
Mint inv() {return this->pow(MOD - 2);}
Mint operator + (int a) const {return Mint((v + a) % MOD);}
Mint operator + (const Mint &a) const {return Mint((v + a.v) % MOD);}
Mint& operator += (int a) {
v = (v + a) % MOD;
return *this;
}
Mint& operator += (const Mint &a) {
v = (v + a.v) % MOD;
return *this;
}
Mint operator - (int a) const {return Mint((v - a + MOD) % MOD);}
Mint operator - (const Mint &a) const {return Mint((v - a.v + MOD) % MOD);}
Mint& operator -= (int a) {
v = (v - a + MOD) % MOD;
return *this;
}
Mint& operator -= (const Mint &a) {
v = (v - a.v + MOD) % MOD;
return *this;
}
Mint operator * (int a) const {return Mint(((long long)v * a) % MOD);}
Mint operator * (const Mint &a) const {return Mint(((long long)v * a.v) % MOD);}
Mint& operator *= (int a) {
v = ((long long)v * a) % MOD;
return *this;
}
Mint& operator *= (const Mint &a) {
v = ((long long)v * a.v) % MOD;
return *this;
}
Mint operator / (int a) const {return Mint(v) * Mint(a).inv();}
Mint operator / (const Mint a) const {return Mint(v) * Mint(a).inv();}
Mint& operator /= (int a) {
v = ((long long)v * Mint(a).inv().v) % MOD;
return *this;
}
Mint& operator /= (const Mint &a) {
v = ((long long)v * Mint(a).inv().v) % MOD;
return *this;
}
Mint& operator = (int a) {
v = a;
v %= MOD;
if(v < 0) v += MOD;
return *this;
}
bool operator == (int a) const {return v == a;}
bool operator == (const Mint &a) const {return v == a.v;}
bool operator != (int a) const {return v != a;}
bool operator != (const Mint &a) const {return v != a.v;}
friend ostream& operator << (ostream &os, const Mint &a) {
os << a.v;
return os;
}
};
const int MAX = 100000;
int n;
int r[2 * MAX];
int dp[4 * MAX];
int calcDP(int p) {
memset(dp, 0, sizeof(dp));
int lb = p - r[p] + 2 * n;
dp[p] = 1;
for(int i = p + 1; i < lb; i++) {
dp[i] = dp[i - 1];
if(r[i] == -1) continue;
int pv = i - r[i];
if(pv > p) dp[i] = max(dp[i], dp[pv - 1] + 1);
}
return dp[lb - 1];
}
void solve() {
cin >> n;
memset(r, -1, sizeof(r));
for(int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
if(a > b) swap(a, b);
r[b] = b - a;
}
int ret = 0;
for(int i = 0; i < min(2 * n, 1500); i++) { // dp assuming u use edge i
if(r[i] == -1) continue;
ret = max(ret, calcDP(i));
}
cout << ret << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
// cin >> t;
t = 1;
while(t--) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5944kb
input:
5 1 2 4 10 7 9 3 5 6 8
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5960kb
input:
1 1 2
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 6000kb
input:
2 1 3 2 4
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 2ms
memory: 5960kb
input:
2 1 4 2 3
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'